gridview模板中有button和label 开始时隐藏lable显示button 点击button后隐藏button并显示lable

不包含RowIndex的定义
2024-11-22 03:52:37
推荐回答(2个)
回答1:

一、 加入事件GridView RowCommand
二、给btn加属性 CommandArgument,CommandName






' CommandName="showAndHide" />





后台
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument);
if (e.CommandName=="showAndHide")
{
Label lbl = GridView1.Rows[index].FindControl("LabIsPay") as Label;
Button btn = GridView1.Rows[index].FindControl("ButIsPay") as Button;
lbl.Visible = true;
btn.Visible = false;
}

}

回答2:

Button ButIsPay = (Button)NianDaiGridView.Rows[e.RowIndex].FindControl("ButIsPay");

ButIsPay.Visiable = false
同理:Label