Question

i can't seem to get the columns to show up on the page. I want to show the gridview with the columns, but without any data. How can i do that?

**Presenter.cs**
public DataTable GetAllSelectedColumns(int onderzoekId)
    {
        DataTable dt = new DataTable();
        var onderzoek = OnderzoekModel.GetOnderzoek(onderzoekId);

        foreach (var cn in OnderzoekColumnModel.GetSelectedColumns(onderzoek.OnderzoekId))
        {
            dt.Columns.Add(cn.ColumnName);
        }

        return dt;
    }

**Page.aspx**

<asp:Panel runat="server" ID="pnlContainer" CssClass="onderzoek-data">
                <asp:GridView ID="mainGridViewFixedColumns" runat="server" AutoGenerateColumns="False" ShowHeaderWhenEmpty="True">
                </asp:GridView>
                <asp:GridView ID="mainGridView" runat="server" Font-Size="Small">
                    <HeaderStyle CssClass="GVHeader" />
                    <FooterStyle CssClass="GVFooter" />
                </asp:GridView>
            </asp:Panel>

**Codebehind**
public void DisplayFixedColumns(DataTable data)
    {
        mainGridViewFixedColumns.DataSource = data;
        mainGridViewFixedColumns.DataBind();
    }
Was it helpful?

Solution 2

The solution from hutchonoid did the trick. I've tried that before but crazily now it works!

I have a populated gridview and a non-populated gridview now. How will i dynamically get the same styling on both headers?

OTHER TIPS

You should be able to add an 'Empty' template to your gridview the same as you would add an 'Edit' template. The 'Empty' template would display if there is no data to show.

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top