C# 数据网格数据绑定字段标题文本在c中的更改#
我有一个datagrid,其中有一个BoundColumn,我正在尝试更改页面加载时的标题文本。我试过这个C# 数据网格数据绑定字段标题文本在c中的更改#,c#,asp.net,datagrid,boundfield,headertext,C#,Asp.net,Datagrid,Boundfield,Headertext,我有一个datagrid,其中有一个BoundColumn,我正在尝试更改页面加载时的标题文本。我试过这个 <asp:datagrid id="dgdata" runat="server" Width="658px" CellPadding="2" PageSize="2" DataKeyField="Name" AutoGenerateColumns="False" ShowFooter="True" BorderColor="AliceBlue" O
<asp:datagrid id="dgdata" runat="server" Width="658px" CellPadding="2" PageSize="2" DataKeyField="Name"
AutoGenerateColumns="False" ShowFooter="True" BorderColor="AliceBlue" OnItemDataBound="dgTranscript_ItemDataBound">
<Columns>
<asp:BoundColumn DataField="Name" HeaderText="" ItemStyle-VerticalAlign="Top"></asp:BoundColumn>
</Columns>
</asp:datagrid>
我想将文本设置为标签内的文本,但如果我说没有标签,它就不能工作
dgdata.Columns[1].Visible = true;
dgdata.Columns[1].HeaderText = "Some Text";
绑定数据
DataSet ds;
DataRow drClient = null;
dgdata.Columns[1].HeaderText = lblAverage.Text; // Here before the Daatabind I set the text to be that label
DataConn.WebExecute(out ds);
DataConn.Bind(dgTranscript, ds);// This binds the data to the datagrid
它将文本显示为标题,但当我尝试在任何字符串或标签文本中下注时,它拒绝整个标题消失
提前谢谢。致以最诚挚的问候如果在数据网格上调用
DataBind
后设置了lblAverage
的值,则标头将保持为空
这很有效
lblAverage.Text = "Some Text";
dgdata.Columns[0].HeaderText = lblAverage.Text;
dgdata.DataSource = mySource;
dgdata.DataBind();
虽然这不会
lblAverage.Text = "Some Text";
dgdata.DataSource = mySource;
dgdata.DataBind();
dgdata.Columns[0].HeaderText = lblAverage.Text;
你可以试试这个
好的,是的,那没用。让我补充更多关于如何将其绑定到数据以及在何处设置headertextNope先生,我只想设置位于顶部的一列的标题,而不是添加另一行
lblAverage.Text = "Some Text";
dgdata.DataSource = mySource;
dgdata.DataBind();
dgdata.Columns[0].HeaderText = lblAverage.Text;
<asp:Label ID="lblAverage" runat="server" Text="Header Value"></asp:Label>
<asp:DataGrid ID="dgdata" runat="server" Width="658px" CellPadding="2" PageSize="2" DataKeyField="Name"
AutoGenerateColumns="False" ShowFooter="true" ShowHeader="true" BorderColor="AliceBlue">
<Columns>
<asp:TemplateColumn>
<HeaderTemplate>
<asp:Label ID="lblheader" runat="server" Text='<%# lblAverage.Text %>'></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblvalue" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>