Display database data in Gridview in asp.net with c#

Posted by Unknown On Friday, 8 March 2013 0 comments

First of all you have to create sql connection with the database...
            For this see the following link


now use the following code for gridview bind in button click event...

protected void Button1_Click(object sender, EventArgs e)
    {
               con.open();
               SqlDataAdapter adp=new SqlDataAdapter("Select * from Emp",con);
               DataTable dt=new DataTable();
               adp.Fill(dt);
                GridView1.DataSource=dt;
                 GridView1.Databind();
    }

0 comments:

Post a Comment