Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/309.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# 了解ID是否与我拥有的内容相符-如保留内容_C#_Asp.net_Checkbox - Fatal编程技术网

C# 了解ID是否与我拥有的内容相符-如保留内容

C# 了解ID是否与我拥有的内容相符-如保留内容,c#,asp.net,checkbox,C#,Asp.net,Checkbox,如何将复选框放入中继器中,并且该复选框必须具有Id,并且是唯一的 例如,当我单击2和5并通过按钮更新antalt时,我如何抓取复选框,我不能使用普通复选框,但可以使用普通复选框 shop.aspx <asp:Repeater ID="RepeaterList" runat="server"> <ItemTemplate> <tr> <t

如何将复选框放入中继器中,并且该复选框必须具有Id,并且是唯一的

例如,当我单击2和5并通过按钮更新antalt时,我如何抓取复选框,我不能使用普通复选框,但可以使用普通复选框

shop.aspx

<asp:Repeater ID="RepeaterList" runat="server">
                <ItemTemplate>
                    <tr>
                        <td>
                            <input  id="CheckboxValue" type="checkbox" style="width: 20px;" value="<%# Eval("id") %>" />
                        </td>
                    </tr>
                </ItemTemplate>
            </asp:Repeater>

<asp:Button ID="ButtonUpdate" OnClick="ButtonUpdate_Click" runat="server" CssClass="butikkenClick" Text="Opdatere kurv" />
更新:

<asp:CheckBoxList ID="CheckBoxListList" runat="server">
                            <asp:ListItem Value="<%# Eval("id") %>"></asp:ListItem>
                        </asp:CheckBoxList>

请参阅或回答此相关问题:

可能的示例是,ID存储在
selectedIds
列表中

protected void ButtonUpdate_Click(object sender, EventArgs e)
{
    var selectedIds = new List<string>();
    foreach (ListItem item in CheckBoxListList.Items)
    {
        if (item.Selected) 
        {
           selectedIds.Add(item.Value);
        }
    }
}
protectedvoid按钮更新\单击(对象发送者,事件参数e)
{
var selectedIds=新列表();
foreach(CheckBoxListList.Items中的ListItem项)
{
如果(选定项)
{
选择edids.Add(item.Value);
}
}
}

您可以使用以下技术

  • 在下面的输入复选框中使用RunAt=“Server”,以便从服务器生成的id是唯一的
  • 
    
    您不在此处使用复选框列表有什么原因吗?我已经尝试过了,但它不允许我使用它@stephen.vakili现在更新@stephen.vakili通过将其设置为
    runat=“server”
    protected void ButtonUpdate_Click(object sender, EventArgs e)
    {
        var selectedIds = new List<string>();
        foreach (ListItem item in CheckBoxListList.Items)
        {
            if (item.Selected) 
            {
               selectedIds.Add(item.Value);
            }
        }
    }