Asp.Net Tutorials: How to retrieve data and display it on a webpage on button click?

Try to use Linq to sql.
-Add a linq to sql class to the project.
-Drag and drop your table into the dbml.
-Write the follawing code in your aspx file:

<body>
<form id="form1" runat="server">
<div>
<asp:gridview autogeneratecolumns="true" id="gv1" runat="server">
</asp:gridview>
<asp:button id="btnBind" onclick="btnBind_Click" runat="server" text="Bind">
</asp:button></div>
</form>
</body>

-In the button click of ur code write the following code:
protected void btnBind_Click(object sender, EventArgs e)
{
gv1.DataSource = GetAllDetails();
gv1.DataBind();

}
public IEnumerable GetAllDetails()
{
DataClassesDataContext dc = new DataClassesDataContext();
return dc.Employees;
}
For more information on data binding Click here

Comments