本文介绍了在asp.net页面中使用用户控件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用用户控件并调用后面的代码。
当我调用用户控件驻留控件时,下拉列表选择已更改我写了这段代码来查找控件。但它显示错误,如将system.httmlcontrol.cell转换为系统.web.control
i二手代码为:
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:
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();
}
推荐答案
引用:
好的我得到了解决方案
OK i got the solution
DropDownList ddl = (DropDownList)sender;
UserControl uc = (UserControl)ddl.NamingContainer;
这篇关于在asp.net页面中使用用户控件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!