更改gridview.net c#外部按钮的标签文本



下面的代码只适用于GridViewCommandEventArgs,但这次我想在按钮单击上使用这种方法。如何修改此代码,以便将其用于按钮单击。我正在寻找改变文本与一个按钮,是gridview之外。

GridViewRow row = (GridViewRow)((Button)e.CommandSource).NamingContainer;
Label label = row.FindControl("lbl_reviewDate") as Label;
label.Text = DateTime.Now.Date.ToString("d");
Label labelID = row.FindControl("lbl_id") as Label;

希望对您有所帮助:

  protected void btn_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow row in YourGridviewName.Rows)
        {
          Label label = row.FindControl("lbl_reviewDate") as Label;
          label.Text = DateTime.Now.Date.ToString("d");
          Label labelID = row.FindControl("lbl_id") as Label;
        }
    }

最新更新