Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Inside of a datagridview I have a template column with a drop down list in the header. I've named the ddl in my asp but in my code behind it's not finding it. any suggestions?
The code is as follows:

ASP.NET
<asp:TemplateField HeaderText="BMOS" SortExpression="BMOS">
<HeaderTemplate>
<asp:Label ID="bMOSLabel" runat="sserver" Text="BMOS">
<asp:DropDownList ID="bMOSDDL" runat="server"
onselectedindexchanged="bMOSDDL_SelectedIndexChanged">

</HeaderTemplate>

C#
protected void bMOSDDL_SelectedIndexChanged(object sender, EventArgs e)
{
con.Open();
sql = bMOSDDL;
cmd = new SqlCommand(sql, con);
total_Gridview.DataSource = cmd.ExecuteReader();
total_Gridview.DataBind();
con.Close();
}


the bMOSDDL inside the protected void brings up the error that the name does not exist in the current context. Anyone have a solution for this?

I would also like to add that my boss doesn't even know why it isn't loading. I could really use some assistance with this. I've been able to go into the constructor and manually put the object in there and it remove the error but as soon as I run it, the web page displays the exact same error.

Thanks in advance,
Sean8084
Posted
Updated 9-Sep-11 10:11am
v2

1 solution

try this
as i understand u want to access your dropdownlist am i right?

(DropDownList)Gv_Data.HeaderRow.FindControl("bMOSDDL");
 
Share this answer
 
Comments
Sean8084 12-Sep-11 11:18am    
I'm getting error message like "Invalid token '(' in class, struct, or interface member declaration" am I using it wrong?
[no name] 12-Sep-11 12:40pm    
send me your code excataly

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900