简体   繁体   English

如何从使用newCell.Text .cs文件构建的多个复选框中检索数据

[英]How to retrieve data from multiple checkbox which is built from .cs file with newCell.Text

I'm new at C# and I'm trying to retrieve data from multiple checkbox and I built it from .cs file with C# code. 我是C#的新手,正尝试从多个复选框中检索数据,并使用C#代码从.cs文件构建了该数据。

These are the codes 这些是代码

newCell.Text += "<table id=\"CheckBoxList1\" class=\"checkboxlist\"><tbody>";
newCell.Text += "<tr><td>";
newCell.Text += "<input class=\"styled\" id=\"CheckBoxList1_0\" type=\"checkbox\" 
value=\"Value\" name=\"CheckBoxList1$\"></input>";
newCell.Text += "<label for=\"CheckBoxList1_0\">Text</label></td></tr>";
newCell.Text += "</tbody></table>";

There are 2 datas in database and I fetch them using these codes. 数据库中有2个数据,我使用这些代码来获取它们。 I want to retrieve data(s) to TextBox which checkbox is selected. 我想将数据检索到已选中复选框的TextBox。

Thank you 谢谢

All the post back data exist on the Request.Form and to get one of them you use the name parameter of your control, in your case: 所有回发数据都存在于Request.Form ,要获得其中的一种,您可以使用控件的name参数,在这种情况下:

Request.Form["CheckBoxList1$"]

When you have a dynamic named control from asp.net you use the UniqueID of the control, as: 当您从asp.net获得动态命名控件时,可以使用该控件的UniqueID ,如下所示:

Request.Form[ControlID.UniqueID]

or in most case the asp.net is control the post back data and add it to some value of the control, eg on TextBoxes, the .Text keep the data. 或在大多数情况下,asp.net是控件回发数据并将其添加到控件的某个值,例如在TextBoxes上, .Text保留数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM