我有一个gridview,我想动态更改标题的名称。有可能的 ? 我有这段代码:
OracleCommand cmdReqStockComp = new OracleCommand(reqStockCompTotal);
cmdReqStockComp.Connection = oConnexion;
OracleDataReader readerReqStockComp = cmdReqStockComp.ExecuteReader();
// ************** ETAPE 2 : On remplit la GridView ************ //
// On lie le résultat de la requête à la GridView
gvReportingStockComp.DataSource = readerReqStockComp;
gvReportingStockComp.DataBind();
这个aspx代码:
<asp:GridView ID="gvReportingStockComp" runat="server" AutoGenerateColumns="false" Visible="false">
<Columns>
<asp:BoundField DataField="cod_wo" HeaderText="N° OF" />
<asp:BoundField DataField="composant" HeaderText="Composant" />
<asp:BoundField DataField="BESOIN" HeaderText="Besoin/OF" />
<asp:BoundField DataField="BESOIN_T" HeaderText="Besoin total" />
<asp:BoundField DataField="stock_dispo" HeaderText="Stock dispo" />
<asp:BoundField DataField="QTE_RESTANTE" HeaderText="Qte restante" />
</Columns>
</asp:GridView>
谢谢:)
答案 0 :(得分:2)
在非常基础的层面上你可以做到
gvReportingStockComp.Columns[0].HeaderText = "New Header for First Column";
答案 1 :(得分:2)
最好使用此
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[0].Text = "HeaderText";
}
而不是
gvReportingStockComp.Columns[0].HeaderText = "New Header for First Column";
这^对我不起作用。
答案 2 :(得分:1)
必须使用Preload事件来更新已排序列的Headertext。我的代码在UpdatePage调用中从DB获取UIlabels,然后GetUIText获取一个标签。将HTML中的HeaderText设置为更新文本的大小写。
Protected Sub Page_preLoad(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreLoad
If UpdatePage(Page.Controls, UIsetBase, "122000," + BldCommonScreen) = False Then
SetMasterErrMsg(Master, "blderrmsg", Session("ErrorMsg"))
End If
For Each Col In OpenTestGridView.Columns
Dim ht As String = Col.HeaderText
Select Case ht
Case "1"
Col.HeaderText = GetUILabel("114100")
Case "2"
Col.HeaderText = GetUILabel("114101")
Case "3"
Col.HeaderText = GetUILabel("114102")
Case "4"
Col.HeaderText = GetUILabel("114103")
Case "5"
Col.HeaderText = GetUILabel("114104")
Case "6"
Col.HeaderText = GetUILabel("114105")
Case "7"
Col.HeaderText = GetUILabel("114008")
Case "8"
Col.HeaderText = GetUILabel("123158")
End Select
Next
End Sub