|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
trying to display header onlyretrieve 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(); *** Sent via Developersdex http://www.developersdex.com *** There is no need to use TemplateColumns. Use BoundColumns.
Eliyahu Show quoteHide quote "David Cho" <profnac***@yahoo.com> wrote in message news:eZeHaaRTFHA.544@TK2MSFTNGP15.phx.gbl... > 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(); > > *** Sent via Developersdex http://www.developersdex.com *** Eliyahu,
Well, using BoundColumn as opposed to TemplateColumn does not display the columns when the DataSource has no records. Did you understand what I was trying to accomplish here? *** Sent via Developersdex http://www.developersdex.com *** Yes, I did. And the headers are displayed perfectly regardless of the number
of records in the datasource. The typical scenario is when you run a query, populate the dataset and databind the grid. If the query returns an empty result set, you will still see the headers. I have this scenario working in tens of pages. In your code you set DataSource to null. I don't believe it's the reason for your problem, but it does look a bit odd. Eliyahu Show quoteHide quote "David Cho" <profnac***@yahoo.com> wrote in message news:eKybNgzTFHA.1148@tk2msftngp13.phx.gbl... > Eliyahu, > > Well, using BoundColumn as opposed to TemplateColumn does not display > the columns when the DataSource has no records. Did you understand what > I was trying to accomplish here? > > *** Sent via Developersdex http://www.developersdex.com ***
I've lost my drop down list box!
Columns are displayed twice binding ArrayLists to DataGrids-- how to name the columns? DataRowView - deleting rows: A little quiz -or- Why doesn't this work... Show Date only from DateTime in DataGrid Wrong window gets the content Export to excel problem MXDatagrid paging problem ItemStyle question Datagrid Moving up and down |
|||||||||||||||||||||||