Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在html表格的不同单元格中显示asp.net复选框列表项_C#_Asp.net - Fatal编程技术网

C# 在html表格的不同单元格中显示asp.net复选框列表项

C# 在html表格的不同单元格中显示asp.net复选框列表项,c#,asp.net,C#,Asp.net,如中所述 链接,我可以在asp.net Web表单页面中创建复选框列表 我想在html表格的不同行中显示每个listItem,因为用户将选择一些显示在不同行中的文件。每行都有一个复选框。用户可以选择显示在多行中的多个文件。我如何实现这一点 以下是我的代码,需要替换为asp:Checkbox: <td valign=bottom align='center' bgcolor='#DA8191'> <input type='checkBox' name=chkOnline val

如中所述 链接,我可以在asp.net Web表单页面中创建复选框列表

我想在html表格的不同行中显示每个listItem,因为用户将选择一些显示在不同行中的文件。每行都有一个复选框。用户可以选择显示在多行中的多个文件。我如何实现这一点

以下是我的代码,需要替换为asp:Checkbox:

<td valign=bottom align='center'  bgcolor='#DA8191'>
<input type='checkBox' name=chkOnline value='abc'>
<td>

上面的代码放在一个循环中,所以复选框列表项的数量取决于从数据库传入的文件


提前谢谢。

你的问题需要充实一下

当您使用asp.net时,我想您也在使用MVC。所以当你说file时,我想象它是你的控制器传递给视图的任何东西。在这种情况下,必须迭代模型。所以,我想你需要这样的东西:

@model ...

...

@foreach (var s in Model){
<tr>
  <td valign=bottom align='center'  bgcolor='#DA8191'>
    <input type='checkBox' name=chkOnline value='abc'>
  </td>
</tr>
}

...
@model。。。
...
@foreach(模型中的var s){
}
...

然后,您可以访问for中模型的任何属性,从而根据需要生成复选框。

您可以使用数据库或其他来源的值从代码隐藏中填充复选框列表

<asp:CheckBoxList ID="CheckBoxList1" runat="server"></asp:CheckBoxList>

事实上,他提到了
asp:Checkbox
标记和
asp.net web表单页面
表明他使用的是asp.net web表单。不,我没有使用MVCI,我想在html下的特定位置绑定每个复选框。我如何通过使用落后的代码来做到这一点呢?那么使用单独的复选框控件,而不是复选框列表就更容易了。
for (int i = 0; i < 5; i++)
{
    CheckBoxList1.Items.Insert(i, new ListItem("Value " + (i + 1), i.ToString(), true));
}
int i = 0;
while (reader.Read())
{
    CheckBoxList1.Items.Insert(i, new ListItem(reader["ColumnA"].ToString(), reader["ColumB"].ToString(), true));
    i++;
}