本文介绍了复选框检查asp.net中的客户端脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有动态复选框和下拉框。
在此我需要编写客户端脚本来隐藏和显示下拉框。
i strucked.can任何人让我摆脱这个问题
i have dynamic check box and dropdown boxes.
in this i need to write client side script to hide and visible of dropdown box.
i strucked.can any one make me out of this issue
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
try
{
DataSet ds = objConfig.GetPositions();
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
HtmlTableRow tr = new HtmlTableRow();
HtmlTableCell tc = new HtmlTableCell();
tc.Align = "Left";
CheckBox _checkbox = new CheckBox();
DropDownList _DropDown = new DropDownList();
_checkbox.ID = "chk_" + ds.Tables[0].Rows[i]["Widget_ID"].ToString();
_checkbox.Text = ds.Tables[0].Rows[i]["Widget_Name"].ToString();
_DropDown.ID = "ddl_" + ds.Tables[0].Rows[i]["Widget_ID"].ToString();
_DropDown.DataSource = ds;
_DropDown.DataValueField = "Widget_ID";
_DropDown.DataTextField = "Widget_ID";
_DropDown.DataBind();
_DropDown.Style.Add("display", "none");
///////////////////////
//everything is working fine except below code
String scriptText = "";
scriptText += "function TogglePositionDDL(ctrl){";
scriptText += " spanCounter.innerText = " +
" document.forms[0]._checkbox.value.length";
scriptText += "}";
ClientScript.RegisterClientScriptBlock(this.GetType(), "CounterScript", scriptText, true);
_checkbox.Attributes.Add("onchecked", "TogglePositionDDL()");
/////////////////////////
tc.Controls.Add(_checkbox);
tr.Cells.Add(tc);
HtmlTableCell tc1 = new HtmlTableCell();
tc1.Align = "Left";
tc1.Controls.Add(_DropDown);
tr.Cells.Add(tc1);
tblWidgets.Rows.Add(tr);
}
}
} }
推荐答案
///////////////////////
working code
String scriptText = "";
scriptText = "function ToggleDDL(chk, ddl) { if (chk.checked) { ddl.style.display=''; } else { ddl.style.display='none'; }}";
ClientScript.RegisterClientScriptBlock(this.GetType(), "CounterScript", scriptText, true);
_checkbox.Attributes.Add("onclick", "ToggleDDL(ctl00_Mdi_" + _checkbox.ID + ", ctl00_Mdi_" + _DropDown.ID + ")");
/////////////////////////
这篇关于复选框检查asp.net中的客户端脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!