gpt4 book ai didi

c# - GridView 更改标题文本

转载 作者:行者123 更新时间:2023-11-28 15:40:06 30 4
gpt4 key购买 nike

复杂性在于网格应该具有AutoGenerateColumns = true。我无法使用 TemplateField 等,因此不允许使用 aspx,只允许 .cs 文件操作。要求:

  • 网格应该自动生成
  • 允许排序和分页

我不知道Asp.Net什么时候填充标题行,但他在内心深处这样做了,因为当PreRenderRowDataBound等上升时,标题行仍然是空的。如果我重命名它,它就可以工作,但在这种情况下,Asp.Net 将其呈现为纯文本。好的,我正在硬编码回发网址并重试,但没有成功,这段代码

private void FillHeaders()
{
const string linkText = @"<a href=""javascript:__doPostBack('ctl00$PlaceHolderMain$AuditGridView','Sort${0}')"">{1}</a>";
bool a = true;
if (a)
for (int i = 0; i < LanitAudit.Properties.Length; i++)
{
AuditGridView.HeaderRow.Cells[i].Text = string.Format(linkText, LanitAudit.Properties[i].Key, LanitAudit.Properties[i].Value);
}
}
}

出现异常:

Invalid postback or callback argument. Event validation is enabled using in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

我还是希望我不能使用客户端JS。

<小时/>

Tnx 寻求答案,但我的问题可能格式错误。是的,我可以替换标题文本,但在它之后我无法对 gridview 进行排序(请参阅第二个要求)。屏幕如下。如您所见,我无法单击“新标题文本”,它是纯文本。但是,如果我尝试自己使用 __doPostBack,我会收到一个错误,您可以在上面看到。 enter image description here

最佳答案

试试这个,下面是在网格的 RowDataBound 事件上更改第一列和网格。

protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == System.Web.UI.WebControls.DataControlRowType.Header)
{
e.Row.Cells[0].Text = "test";
}
}

请参阅下面的更改,这可能是您正在尝试做的事情。

protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == System.Web.UI.WebControls.DataControlRowType.Header)
{
//e.Row.Cells[0].Text = "test";

LinkButton lnk1 = e.Row.Cells[0].Controls[0] as LinkButton;
lnk1.Text = "test";
}
}

关于c# - GridView 更改标题文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24161685/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com