How to Bind Records Web Application Gridview and Windows Application Grid View
In this Article, I am going to explain about how to bind the records using web application and windows application controls.I have implemented gridview control for ASP.net and datagridview control for windows application .I have post source with snapshots below
In this Article, I am going to explain about how to bind the records using web application and windows application controls.I have implemented gridview control for ASP.net and datagridview control for windows application .I have post source with snapshots below
client side and server side
<form id="form1" runat="server">
<asp:GridView runat="server" ID="grd1">
</asp:GridView>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</form>
Server side code,
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection sqlcon = new SqlConnection("Data Source=PC;Initial Catalog=Test;User id=sa;Pwd=123;Integrated Security=False;");
SqlDataAdapter sqladp = new SqlDataAdapter("Select * from [Customer]", sqlcon);
DataTable dt = new DataTable();
sqladp.Fill(dt);
grd1.DataSource = dt;
grd1.DataBind();
}
2.Windows application dataGridview bind the records
Source code
private void button1_Click(object sender, EventArgs e)
{
SqlConnection sqlcon=new SqlConnection("Data Source=PC;Initial Catalog=Test;User id=sa;Pwd=123;Integrated Security=False;");
SqlDataAdapter sqladp = new SqlDataAdapter("Select * from [Customer]",sqlcon);
DataTable dt=new DataTable();
sqladp.Fill(dt);
dataGridView1.DataSource = dt;
}
see this image given below