如何在asp.net 4.0中附加复选框CommandName和CommandArgument

时间:2014-05-05 08:24:58

标签: c# asp.net

我只想将命令名和命令参数附加到复选框,以便在运行时从复选框中触发重复项目命令。这是我的设计代码:

<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
                                    <ContentTemplate>
                                    <asp:Repeater ID="Repeater_Category" runat="server" onitemcommand="Repeater_Category_ItemCommand">
                                    <ItemTemplate>
                                        <asp:CheckBox ID="CheckBox1" runat="server" Text='<%#Eval("CategoryName")%>' AutoPostBack="true" CommandName="Select" CommandArgument='<%#Eval("Id")%>'/>
                                        <asp:HiddenField ID="hdValue" runat="server" Value='<%#Eval("Id")%>' />
                                    </ItemTemplate>
                                      <SeparatorTemplate>&nbsp;&nbsp;</SeparatorTemplate>
                                    </asp:Repeater>
                                    </ContentTemplate>
                                        <Triggers>
                                            <asp:AsyncPostBackTrigger ControlID="Repeater_Category" 
                                                EventName="ItemCommand" />
                                        </Triggers>
                                    </asp:UpdatePanel>

这是我的Repeater项目命令事件代码:

 protected void Repeater_Category_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName.Equals("Select"))
        {
            List<int?> GroupByCategory = null;
            if (e.CommandArgument.Equals("-1"))
            {
                GroupByCategory.Clear();
                Session["GroupByCategory"] = null;
                this.FillGrid((String)Session["GroupByText"] ?? null, (List<int?>)Session["GroupByCategory"] ?? null, (List<int?>)Session["GroupByStatus"] ?? null, (String)Session["ColumnName"] ?? null, (String)Session["SearchText"] ?? null);
            }
            else
            {
                GroupByCategory.Add(int.Parse(e.CommandArgument.ToString()));
                Session["GroupByCategory"] = GroupByCategory;
                this.FillGrid((String)Session["GroupByText"] ?? null,(List<int?>)Session["GroupByCategory"] ?? null,(List<int?>)Session["GroupByStatus"] ?? null,(String)Session["ColumnName"] ?? null, (String)Session["SearchText"] ?? null);
            }
        }
    }

0 个答案:

没有答案