how to bind from database to a datalist using textbox

HOUSSEM MAHJOUBI 286 Reputation points
2021-01-26T15:54:19.04+00:00

Hi members
i want get the data from the db using a textbox and populated to a datalist
please help

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,573 questions
0 comments No comments
{count} votes

Accepted answer
  1. Sam Wu-MSFT 7,526 Reputation points Microsoft Vendor
    2021-01-27T03:01:52.263+00:00

    Hi @HOUSSEM MAHJOUBI ,

    I wrote a demo for you, you can use it as a reference.

    <form id="form1" runat="server">  
            <div>  
                <asp:DataList ID="dlCustomers" runat="server" DataSourceID="SqlDataSource1">  
                    <ItemTemplate>  
                        <table border="1">  
                            <tr>  
                                <td>EmpId:</td>  
                                <td><asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("EmpId") %>'></asp:TextBox></td>  
                            </tr>     
                            <tr>  
                                <td>EmpName:</td>  
                                <td><asp:TextBox ID="TextBox2" runat="server" Text='<%# Eval("EmpName") %>'></asp:TextBox></td>  
                            </tr>  
                            <tr>  
                                <td>EmpCity:</td>  
                                <td><asp:TextBox ID="TextBox3" runat="server" Text='<%# Eval("EmpCity") %>'></asp:TextBox></td>  
                            </tr>  
                        </table>  
                    </ItemTemplate>  
                </asp:DataList>  
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TestConnectionString %>" SelectCommand="SELECT [EmpId], [EmpName], [EmpCity] FROM [Employee]"></asp:SqlDataSource>  
            </div>  
        </form>  
    

    60842-50.png

    I suggest you use the Label control to populated the DataList, I think it looks a little more beautiful than the textbox control.

    More information about the use of DataList control you can refer to this link: DataList-control-Tutorial-with-example-in-ASPNet.aspx

    Best regards,
    Sam


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.