Learn GridView - Part I

hi this is zubair, i going to teach gridview with easiest way.

First Step: first i describe you about our database in sql server 2005.
Database name is publicDB, Table name is sqltest which have two columns Name and City.

Second Step:
Open the visual web developer 2005.
click on new tab -> select new website -> give it name as u wish.

Third Step:
now on the default.aspx page drag the gridview control from the control box.

write the code in web.config as follows:


connectionString="Server ='YourServerName'
Database='publicDb'
Trusted_Connection='True' "
providerName="System.Data.SqlClient" />


Fourth Step:

now we are going to write the coding in Default.aspx.cs
open the Default.aspx.cs and write the code below.

protected void Page_Load(object sender, EventArgs e)
{
BindData();
}

public void BindData()
{
SqlConnection con = new SqlConnection(ConfiguratonManager.ConnectionStrings["ConnectionString"].ConnectionString);

SqlDataAdapter ad = new SqlDataAdapter("Select * from sqltest",con);

DataSet ds = new DataSet();

ad.Fill(ds);

GridView1.DataSource = ds;
GridView1.DataBind();

}

1 comments:

Anonymous said...

Gridview control is so huge. From that I mean that the class is so huge. How can I make sure that I know everything htere is to know about gridview? That is, is there a way to learn everything about gridview?