GridView 中RowCommand事件用法

GridView 中RowCommand事件用法
//如果我照提示说的把enableEventValidation的值设为False,就获取不到e.CommandArgument的值.
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {

        if (e.CommandName == "Del")
        {
            
            Response.Write("删除");

            GridViewRow row = (GridViewRow)((Control)e.CommandSource).Parent.Parent;

            string index = row.Cells[3].Text;//当前行第一个单元格的值

          
            object myCommandArgument = e.CommandArgument;
            
            Response.Write(myCommandArgument);

            Response.Write(index);

        }

        if (e.CommandName == "Upd")
        {
            
            Response.Write("修改");

            string dw = e.CommandArgument.ToString();

            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                string id = Convert.ToString(GridView1.Rows.Cells[0].Text);

                if (id == dw)
                {
                    Response.Write(id);

                }

            }
          
        }

    }



<asp:GridView ID="GridView1" DataKeyNames="ItemID" runat="server" Width="100%" AutoGenerateColumns="False"    
                  

                    OnRowCommand="GridView1_RowCommand"
>
                    
                    <Columns>
                      
                        <asp:BoundField HeaderText="宠物ID" DataField="ItemID"  ReadOnly="True"/>
                      
                        <asp:BoundField HeaderText="宠物名称" DataField="ShangpinName" />
                        
                        <asp:BoundField HeaderText="售价" DataField="Price" DataFormatString="{0:c}" >
                            <ItemStyle HorizontalAlign="Center" />
                            <HeaderStyle HorizontalAlign="Center" />
                        </asp:BoundField>
                        
                        <asp:BoundField HeaderText="数量" DataField="Quantity" >
                            <ItemStyle HorizontalAlign="Center" />
                            <HeaderStyle HorizontalAlign="Center" />
                        </asp:BoundField>
                        <asp:ButtonField HeaderText="选择" Text="选择" CommandName="select" >
                        <ItemStyle HorizontalAlign="Center" />
                        <HeaderStyle HorizontalAlign="Center" />
                        </asp:ButtonField>
                      
                      
                        <asp:TemplateField HeaderText="选择">
                            <ItemTemplate>
                                <asp:LinkButton ID="LinkButton2" runat="server" CommandArgument='<%# Eval("ItemID")+"*"+Eval("ShangpinName") +"*"+Eval("Price")+"*"+Eval("Quantity")+"*"+Eval("ListPrice")%>'
                                    CommandName="Del">选择</asp:LinkButton>
                                <asp:LinkButton ID="LinkButton3" runat="server" CommandArgument='<%# Eval("ItemID") %>' CommandName="Upd">选择</asp:LinkButton>
                            </ItemTemplate>
                        </asp:TemplateField>
                        
                        
                        <asp:CommandField ShowEditButton="True" />
                      
                <asp:TemplateField>
                    <HeaderTemplate>
                        全选<asp:CheckBox ID="CheckBox2" runat="server" OnCheckedChanged="CheckBox2_CheckedChanged" AutoPostBack="True" />
                    </HeaderTemplate>
                    <ItemTemplate>
                        <asp:CheckBox ID="CheckBox1" runat="server" />
                    </ItemTemplate>
                </asp:TemplateField>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值