从GridView asp.net c外部的按钮更改标签文本#

时间:2015-09-25 06:22:50

标签: c# asp.net gridview

下面的代码仅适用于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;

1 个答案:

答案 0 :(得分:0)

我希望这会有所帮助:

  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;
        }
    }