Wednesday, April 6, 2011

Populate Dropdown lists in GridView in asp.net

How to do it is :


Write a method which will get the values from the database and it returns a dataset:

--------------------------------------------------------------------------
// This method populates the DropDownList

public DataSet PopulateControls()
{
SqlConnection myConnection = new SqlConnection(GetConnectionString());
SqlDataAdapter ad = new SqlDataAdapter("SELECT [Name] FROM tblPerson",
myConnection);
DataSet ds = new DataSet();
ad.Fill(ds, "tblPerson");
return ds;
}
--------------------------------------------------------------------------


Now inside the itemtemplate tag do the following




Thats it........Done.

No comments:

Post a Comment