以字符串形式获取复选框的选定项
问题描述:
在转发器控制中,我具有带有复选框的公司名称列表....如果我选择公司名称,将对其进行检查.....我在转发器控制中具有for循环,如果选中了这些项,则它进入chk.checked状态..否则在循环之外...如何以字符串形式获取所选公司ID ...请帮助我...尽快
In repeater control , i am having list of company names with checkbox.... if i select the company names it will be checked .....i am having for loop for repeater control ,if the items are checked then it goes into the chk.checked condition..otherwise outside the loop...how to get the selected company id in a string......Please help me...as soon as possible
protected void btnPDF_Click(object sender, EventArgs e)
{
//string memberno = "Repeater items checked:<br/>";
string lblid = string.Empty;
for (int itemcount = 0; itemcount < Rpt_Company.Items.Count; itemcount++)
{
CheckBox chkbox = ((CheckBox)Rpt_Company.Items[itemcount].FindControl("chkbox"));
if (chkbox != null && chkbox.Checked == true)
{
// lblid=Rpt_Company.Items[itemcount].FindControl("chkbox");
// lblid = chkbox.Text;
// memberno += chkbox.Text;
//memberno += (chkbox.Text + "<br/>");
//Literal lbl = (Literal)Rpt_Company.Items[itemcount].FindControl("chkbox");
//Label lbl = (Label)Rpt_Company.Items[itemcount].FindControl("chkbox");
// lblid = lbl.Text;
}
}
答
您可以在btnPDF_Click本身中分配字符串,而不是使用EVAL.
您的代码以任何方式进行回发.只是这样分配
Hi,
Instead of using EVAL you can assign the string in the btnPDF_Click itself.
Any way your code goes for a postback. Just assign like this
TempData.Text = memberno;
认为这会有所帮助.
Think this would help.