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

Santhosh Kumar JayaramanRank #563 · 4.3K reputationPosted Jun 20, 2012, 12:40 AM EDT
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();
}
Aamir KhanRank #7,345 · 243 reputationPosted Jun 20, 2012, 12:47 AM EDT
Santhosh Kumar JayaramanRank #563 · 4.3K reputationPosted Jun 20, 2012, 12:53 AM EDT
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 KhanRank #7,345 · 243 reputationPosted Jun 20, 2012, 1:07 AM EDT
Santhosh Kumar JayaramanRank #563 · 4.3K reputationPosted Jun 20, 2012, 1:09 AM EDT
Santhosh Kumar JayaramanRank #563 · 4.3K reputationPosted Jun 20, 2012, 1:10 AM EDT
Aamir KhanRank #7,345 · 243 reputationPosted Jun 20, 2012, 1:48 AM EDT