Hi,
I give a solution to bind data on dropdown list ,grid view and details view using class file.
At first connect to data base though connection string then check connection and open the connection fill dataset then after bind the control data source to dataset.
i give here class file code:
for drop down list.
public void FillDropDownList(string Str, DropDownList Ddl)
{
if (CheckCon() == true)
{
DataSet Ds = new DataSet();
ExecuteDataset(Str, ref Ds);
Ddl.DataSource = Ds.Tables[0];
Ddl.DataValueField = Ds.Tables[0].Columns[0].ColumnName;
Ddl.DataTextField = Ds.Tables[0].Columns[1].ColumnName;
Ddl.DataBind();
ListItem Li = new ListItem();
Li.Value = "0".ToString();
Ddl.Items.Insert(0, Li);
}
}
for grid view:
public void FillGridView(GridView Grd, string Str)
{
if (CheckCon() == true)
{
Ds = new DataSet();
Da = new SqlDataAdapter(Str, Con);
Da.Fill(Ds, "tab");
Grd.DataSource = Ds.Tables["tab"];
Grd.DataBind();
}
}
for details view:
public void FillDetailsView(DetailsView DeViw, string Str)
{
if (CheckCon() == true)
{
Ds = new DataSet();
Da = new SqlDataAdapter(Str, Con);
Da.Fill(Ds, "tab");
DeViw.DataSource = Ds.Tables["tab"];
DeViw.DataBind();
}
}