Firstly make table in sql server like as:-
Create table college(
id int,
name nvarchar(50),
Category nvarchar(60),
address nvarchar(60),
city nvarchar(50),
phone bigint
);
Then if want to fetech data in DataList than everyone have to define the structure of Datalist:-
<asp:DataList ID="DataList1" runat="server" Width="187px">
<ItemTemplate><table><tr><td><asp:TextBox ID="Textbox1" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"ID") %>'></asp:TextBox></td>
<td><asp:TextBox ID="Textbox2" runat="server" Text='<%#Eval("Name") %>'></asp:TextBox></td>
<td><asp:TextBox ID="Textbox3" runat="server" Text='<%#Eval("Category") %>'></asp:TextBox></td>
<td><asp:TextBox ID="Textbox4" runat="server" Text='<%#Eval("Address") %>'></asp:TextBox></td>
<td><asp:TextBox ID ="Textbox5" runat="server" Text='<%#Eval("City") %>'></asp:TextBox></td>
<td><asp:TextBox ID="Textbox6" runat="server" Text='<%#Eval("Phone") %>'></asp:TextBox></td>
</tr></table></ItemTemplate>
</asp:DataList>
Then write this code into button or pageload:-
Add a Namespace:- Using System.Data.SqlClient;SqlDataAdapter sda = new SqlDataAdapter("Select * from college", "Initial Catalog=Search Engine;Data Source=IICTECH-B337995;Integrated Security=true");
DataSet ds = new DataSet();
sda.Fill(ds);
DataList1.DataSource = ds ;
DataList1.DataBind();
No comments:
Post a Comment