QUESTION POSED ON: 13 July 2005
I need to show a Dropdownlist in page load, and based on my selection from
Dropdownlist I need to populate a Datagrid , the Dropdownlist is independent
of the datagrid . Is it possible to do that.
Please note that the Dropdownlist is independent and not part of the grid .
Based on the selection from the list the grid will be populated.
if(!page.Ispostback)
{
SqlConnection myConnection = new SqlConnection("server=MANSV107;database=EPPRD;uid=kpi_user;
pwd=kpi_user"); myConnection.Open(); SqlDataAdapter myCommand = new SqlDataAdapter("select
name from Plants where p_id not in(5)",myConnection); //SqlDataAdapter myCommand
= new SqlDataAdapter("select * from kpi_conscomp_v where plant like 'Manchester%'and
year='2004'", myConnection); DataSet ds =new DataSet(); myCommand.Fill(ds,"kpi");
DropDownList1.DataSource=ds;
DropDownList1.DataTextField="name";
DropDownList1.DataBind();
/********************************/
// form = (HtmlForm) this.FindControl("Form1"); // form.Controls.Add(
dropdownlist1 ); // DropDownList1.Style["POSITION"]
= "absolute"; DropDownList1.Style["TOP"]
= "120"; }
It is working fine but onselection from the List the Datagrid is not populating.
The code is private void DropDownList1_SelectedIndexChanged(object sender,
System.EventArgs e) { SqlConnection myConnection = new SqlConnection("server=MANSV107;database=EPPRD;uid=kpi_user;
pwd=kpi_user"); myConnection.Open();
SqlDataAdapter da=new SqlDataAdapter("select * from kpi_conscomp_v where
plant like'" + DropDownList1.SelectedValue +"'",myConnection);
DataSet ds=new DataSet(); da.Fill(ds,"KPI"); MyDataGrid.DataSource=ds.Tables["KPI"].DefaultView;
MyDataGrid.DataBind();
}
|