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

编程入门 行业动态 更新时间:2024-10-28 19:20:21

怎么在<a href=https://www.elefans.com/category/jswz/34/1771386.html style=后台获取gridview中某一行的一列"/>

怎么在后台获取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);
            }
        } 

更多推荐

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

本文发布于:2023-07-28 19:35:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1289215.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:后台   gridview

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!