请教后台设置GridView的HeaderText的属性
<asp:GridView ID="gvList" runat="server" Width="100%">
</asp:GridView>
DataTable dt = new DataTable("dtExcel");
dt.Columns.Add("Com_ID");
dt.Columns.Add("Com_Name");
dt.ReadXml(Request.MapPath("Excel.xml"));
this.gvList.DataSource = dt;
//this.gvList.Columns[0].HeaderText = "aa"; //报错
this.gvList.DataBind();
请问一下这个怎么给Com_ID和Com_Name设置一个别名,即是HeaderText
[解决办法]
你在前台绑定的时候就给他设置两个HeaderText 模板
<HeaderTemplate>
在这里写
</HeaderTemplate>
[解决办法]
Dim tcHeader As TableCellCollection = oGridCells tcHeader.Clear() tcHeader.Add(New TableHeaderCell) tcHeader(0).Attributes.Add("rowspan", "2") tcHeader(0).Text = dtGrid.Columns.Item("Com_ID").Caption
[解决办法]
在对数据库中操作的sql语句中字段后空格 加上别名就行
像这样
sleect Com_ID 公司ID.......
[解决办法]
protected void gvList_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
foreach(TableCell cell in e.Row.Cells)
{
cell.Text = "xxxxx";
}
}
}
<asp:GridView ID="gvList" runat="server" OnRowCreated="gvList_RowCreated">
或者protected void gvList_RowDataBound(object sender, GridViewRowEventArgs e)里面