Click here to Skip to main content
15,905,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all....

I have a grid-view on my page and i have used footer row of grid-view to insert new data. The problem that i am facing is that is when there is no data present in the database it is not showing grid-view. But i need grid-view to be shown on the page so that user can enter data. Please help me out.
XML
<asp:GridView DataKeyNames="ID" ID="Grid_Categories" runat="server" AutoGenerateColumns="False"
        Width="250px" onrowcancelingedit="Grid_Categories_RowCancelingEdit"
        onrowdeleting="Grid_Categories_RowDeleting"
        onrowediting="Grid_Categories_RowEditing"
        onrowupdating="Grid_Categories_RowUpdating"
        onselectedindexchanged="Grid_Categories_SelectedIndexChanged"
        onrowcommand="Grid_Categories_RowCommand" ShowFooter="True"
        onrowdatabound="Grid_Categories_RowDataBound" EmptyDataText="no valyue">

    <Columns>
    <asp:TemplateField ItemStyle-Width="165">
    <ItemTemplate>
    <asp:LinkButton runat="server" ID="link_category" Text='<%# Eval("Category") %>' CommandName="Select" CausesValidation="true"></asp:LinkButton>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox runat="server" ID="txtcategory" Text='<%# Eval("Category") %>'></asp:TextBox>
    </EditItemTemplate>

    <FooterTemplate>
    Name &nbsp;&nbsp;
    <asp:TextBox runat="server" ID="txtnewcategory"></asp:TextBox>
    </FooterTemplate>

<ItemStyle Width="165px"></ItemStyle>
    </asp:TemplateField>
    <asp:TemplateField>

    <ItemTemplate>
    <asp:LinkButton runat="server" ID="link_Edit" Text="Edit" CommandName="Edit" CausesValidation="true"></asp:LinkButton>
    &nbsp;&nbsp;
    <asp:LinkButton runat="server" ID="link_Delete" Text="Delete" CommandName="Delete" CausesValidation="true"></asp:LinkButton>
    </ItemTemplate><pre lang="c#">
    <EditItemTemplate>
    <asp:LinkButton runat="server" ID="link_Update" Text="Update" CommandName="Update" CausesValidation="true"></asp:LinkButton>
    &nbsp;&nbsp;
    <asp:LinkButton runat="server" ID="link_Cancel" Text="Cancel" CommandName="Cancel" CausesValidation="true"></asp:LinkButton>
    </EditItemTemplate>
    <FooterTemplate>
    <asp:Button runat="server" ID="btn_insert1" Text="Insert" CommandName="Insert" CausesValidation="true" />
    </FooterTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView>
Posted
Updated 2-Jan-12 18:47pm
v2

1 solution

Hi,

you can create EmptyDataTemplate for display header/footer when no data exist.

you can pass whole HTML table inside this template.

hope this will help you

thanks
-amit.
 
Share this answer
 
Comments
abhishekagrwl25 3-Jan-12 2:43am    
i have used EmptyDataTemplate but still it does not showing footer row...
AmitGajjar 3-Jan-12 3:26am    
have you created HTML Table for footer inside EmptyDataTemplate ?
abhishekagrwl25 3-Jan-12 3:45am    
no.... i haven't. the problem that i am facing is that it's not showing footer template field when it's showing empty data template field.
AmitGajjar 3-Jan-12 3:48am    
yes ofcourse when DataSet is empty it will show you EmptyDataTemplate content, what you need to do is create similar Footer in HTML and place that HTML code inside EmptyDataTemplate.
abhishekagrwl25 3-Jan-12 4:14am    
I have done it. Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900