gridview怎么实现点击每行后面的按钮则改行某字段的值减一
展开全部
//给GridView中的按钮添加上次事件:
public void btTest1_Click(object sender, EventArgs e)
{
Button bt = (Button)sender;
GridViewRow tbr = (GridViewRow)bt.Parent.Parent;
int rowIndex = tbr.RowIndex;
//rowIndex是按钮所在的行号,假如你要把第rowIndex行第一列的值-1,过程如下:
int value = Int32.Parse(GridView1.Rows[rowIndex].Cells[0].Text.Trim());
int newValue = value - 1;
string stRresult = newValue.ToString();
GridView1.Rows[rowIndex].Cells[0].Text = stRresult;
}
public void btTest1_Click(object sender, EventArgs e)
{
Button bt = (Button)sender;
GridViewRow tbr = (GridViewRow)bt.Parent.Parent;
int rowIndex = tbr.RowIndex;
//rowIndex是按钮所在的行号,假如你要把第rowIndex行第一列的值-1,过程如下:
int value = Int32.Parse(GridView1.Rows[rowIndex].Cells[0].Text.Trim());
int newValue = value - 1;
string stRresult = newValue.ToString();
GridView1.Rows[rowIndex].Cells[0].Text = stRresult;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询