后台获取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中某一行的一列
发布评论