D
David Cho
I have a form with a datagrid control. And I have a button that will
retrieve data and upon postback, the datagrid gets populated.
What I would like to have is, upon the loading of the form (before
postback), have the datagrid display the header with all the column
headings.
Right now, nothing is visible and the heading does not show unless the
DataSource has at least one row.
I tried the following.
<asp:datagrid id="dgEmployees" ShowFooter="False"
AutoGenerateColumns="False" HorizontalAlign="Center"
BackColor="#eeeeee" Runat="server" DataKeyField="EmployeeID">
<Columns>
<asp:TemplateColumn HeaderText="Last Name">
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem, "LastName")%>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="First Name">
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem, "FirstName")%>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
//code behind
dgEmployees.DataSource = null;
dgEmployees.DataBind();
retrieve data and upon postback, the datagrid gets populated.
What I would like to have is, upon the loading of the form (before
postback), have the datagrid display the header with all the column
headings.
Right now, nothing is visible and the heading does not show unless the
DataSource has at least one row.
I tried the following.
<asp:datagrid id="dgEmployees" ShowFooter="False"
AutoGenerateColumns="False" HorizontalAlign="Center"
BackColor="#eeeeee" Runat="server" DataKeyField="EmployeeID">
<Columns>
<asp:TemplateColumn HeaderText="Last Name">
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem, "LastName")%>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="First Name">
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem, "FirstName")%>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
//code behind
dgEmployees.DataSource = null;
dgEmployees.DataBind();