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