Click here to Skip to main content
15,884,664 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am using using user control and calling to code behind.
when i was calling the user control reside control like drop down list selected changed i write this code to find the control . but it show error like converting error with system.httmlcontrol.cell to system .web.control


i used code is:
C#
protected void ddlDept_SelectedIndexChanged(object sender, EventArgs e)
    { 

  DropDownList dd = (DropDownList)sender;
            string CtrlId = dd.ID;
            int g = Convert.ToInt32(dd.SelectedValue);
            Control cd = dd.Parent;
            UserControl uc = (UserControl)cd;
            DropDownList ddlEmp = (DropDownList)uc.FindControl("ddlEmp");
            DropDownList ddlClass = (DropDownList)uc.FindControl("ddlClass");
            DropDownList ddlDept = (DropDownList)uc.FindControl("ddlDept");
            int acadamic = Convert.ToInt32(Session["AcademicYear"]);
            int userid = Convert.ToInt32(Session["UserRoleId"]);


            DataSet ds = _objDal.getclass(Convert.ToInt32(ddlDept.SelectedValue),userid,acadamic);
            ddlClass.DataSource = ds;
            ddlClass.DataTextField = "ClassName";
            ddlClass.DataValueField = "es_id";
            ddlClass.DataBind();  
}
Posted
Comments
Suvabrata Roy 1-Oct-14 0:44am    
In which line you getting this error? Are you using some kind of data grid?
Member 10229796 1-Oct-14 1:01am    
UserControl uc = (UserControl)cd; in this line i get error like system.web.htmlcontrol.htmlcell to system.web.controls
Suvabrata Roy 1-Oct-14 1:24am    
Where you place that drop down ?

You are accessing its parent but as per your Exception Message its a HtmlControl or most likely a table its not a Server Control that's why its throwing error.
Member 10229796 1-Oct-14 1:29am    
in user control
Samatha Reddy G 1-Oct-14 1:25am    
you are trying to call dropdowns which are there in usercontrol am i right?

1 solution

I was about to answer this, but OP has commented. :) Adding this to move it from unanswered list.
Quote:
OK i got the solution

C#
DropDownList ddl = (DropDownList)sender;
UserControl uc = (UserControl)ddl.NamingContainer;
 
Share this answer
 

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