Hi friends,
i have a requirement where i have to fill a dropdown in a Gridview on Selection or IndexChange of another Dropdown Control which is not inside of any Gridview.
i have done some code but i get the Null value;
code is as below
protected
{
void DrpProtocol_ID_SelectedIndexChanged(object sender, EventArgs e)//DataRowView drv = e.Row.DataItem as DataRowView;
dt = objDal.GetDataQry(
{
ddlCity = (
DataSet dt = new DataSet();"select InvId from dbo.InvDetails where ProtocolId='" + DrpProtocol_ID.SelectedItem.Text + "'", Convert.ToString(ConfigurationManager.ConnectionStrings["ConDMUtils_BackUp"].ConnectionString));DropDownList ddlCity = new DropDownList();foreach (GridViewRow row in GridView1.Rows)DropDownList)row.FindControl("ddlSite");//dropdown inside Gridview}
{
ddlCity.DataSource = dt.Tables[0];
if (ddlCity != null)//ddlCity.DataTextField = "InvId";ddlCity.DataValueField = "InvId";
ddlCity.DataBind();
}
}
what is the mistake being done
Loading
Aamir KhanPosted Jun 20, 2012, 5:48 AM
Santhosh Kumar JayaramanPosted Jun 20, 2012, 5:10 AM
Santhosh Kumar JayaramanPosted Jun 20, 2012, 5:09 AM
Aamir KhanPosted Jun 20, 2012, 5:07 AM
Santhosh Kumar JayaramanPosted Jun 20, 2012, 4:53 AM
But thats not the dropdownlist in the gridview. You have to set this ddlcity as the dropdown inside gridview (i.e. ddlsite).
Like this.
DropDownList ddlCity = gridViewRow.FindControl("ddlSite") as DropDownList;
Aamir KhanPosted Jun 20, 2012, 4:47 AM
Santhosh Kumar JayaramanPosted Jun 20, 2012, 4:40 AM
After that you didnt set that to ddlsite.
try this,
after populating values to datatable dt, write the below code
foreach (GridViewRow gridViewRow in GridView1.Rows)
{
DropDownList ddlCity = gridViewRow.FindControl("ddlSite") as DropDownList;
ddlCity.DataSource = dt.Tables[0];
if (ddlCity != null)//ddlCity.DataTextField = "InvId";ddlCity.DataValueField = "InvId";
ddlCity.DataBind();
}