怎么在后台获取gridview中某一行的一列

aspx文件中:

<asp:GridView ID="GridView1" runat="server" DataKeyNames="ws_id" AutoGenerateColumns="False" OnRowCommand="GridView1_RowCommand" OnRowDeleting="GridView1_RowDeleting" OnRowUpdating="GridView1_RowUpdating">
                <Columns>
                    <asp:BoundField HeaderText="编号" DataField="ws_id" ReadOnly="true" />
                    <asp:BoundField HeaderText="姓名" DataField="ws_name" ReadOnly="true" />
                    <asp:BoundField HeaderText="性别" DataField="ws_sex" ReadOnly="true" />
                    <asp:BoundField HeaderText="年龄" DataField="ws_age" ReadOnly="true" />
                    <asp:BoundField HeaderText="电话" DataField="ws_phone" ReadOnly="true" />
                    <asp:BoundField HeaderText="地址" DataField="ws_address" ReadOnly="true" />
                    <asp:ButtonField ButtonType="button" HeaderText="删除功能" Text="删除" CommandName="Delete" />
                    <asp:ButtonField ButtonType="button" HeaderText="修改功能" Text="修改" CommandName="Update" />
                </Columns>
            </asp:GridView>

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                int index = Convert.ToInt32(e.CommandArgument);//CommandArgument:获取命令的参数
                GridViewRow row = GridView1.Rows[index];//获取所选行
                string id = row.Cells[0].Text.ToString();//获取第一列

                string sql = "delete from Information where ws_id =" + id;
                if (CommonApp.ExecuteNonQuery(sql) > 0)
                {
                    Response.Write("<script>alert('删除成功!');</script>");
                    data();
                }
                else
                {
                    Response.Write("<script>alert('删除失败!')</script>");
                }
            }
            if (e.CommandName=="Update")
            {
                int index = Convert.ToInt32(e.CommandArgument);/CommandArgument:获取命令的参数
                GridViewRow row = GridView1.Rows[index];//获取所选行
                string id = row.Cells[0].Text.ToString();//获取第一列

                Response.Redirect("WebUpdate.aspx?id=" + id);
            }
        } 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值