我在网格中的Button
内有一个ItemTemplate
。我正在动态分配按钮文本。因为我需要为每个行按钮提供不同的文本。但OnClick
事件未显示更新的文本,而是显示空字符串。请帮忙!!
<asp:TemplateField HeaderText="GetHistory">
<ItemTemplate>
<asp:Button
DataField="GetHistory"
ID="btn_getHistory"
CausesValidation="false"
runat="server"
OnClick="btn_getHistory_Click" Visible="false" />
</ItemTemplate>
</asp:TemplateField>
protected void btn_getHistory_Click(object sender, EventArgs e)
{
//My sender text is showing empty here
}
protected void GridViewTree1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow && e.Row.DataItem != null && !((System.Data.DataRowView)(e.Row.DataItem)).Row.ItemArray[0].ToString().Contains("\\"))
{
Button btn_getHistory = (Button)e.Row.Cells[3].FindControl("btn_getHistory");
if (btn_getHistory != null)
{
btn_getHistory.Visible = true;
var chunks = ((System.Data.DataRowView)(e.Row.DataItem)).Row.ItemArray[0].ToString().Split('_'); // any separator characters
var a = chunks.Take(chunks.Length - 1);
string testsetName = string.Empty;
foreach (string b in a)
{
testsetName = testsetName + b + '_';
}
btn_getHistory.Text = testsetName.ToString().TrimEnd('_');
}
}