Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have created gridview in asp.net website but is not visible
the code is:
ASP.NET
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        AllowPaging="True" BackColor="White" BorderColor="#CC9966" BorderStyle="None" 
        BorderWidth="1px" CellPadding="4" DataSourceID="SqlDataSource1" 
        ShowFooter="True">
        <rowstyle backcolor="White" forecolor="#330099" />
        <columns>
            <asp:TemplateField>
               
                <itemtemplate>
                    <asp:CheckBox ID="CheckBox1" AutoPostBack="true" runat="server" />
                </itemtemplate>
            
            <asp:BoundField DataField="company_id" HeaderText="company_id" ReadOnly="True" 
                SortExpression="company_id" />
            <asp:BoundField DataField="company_name" HeaderText="company_name" 
                SortExpression="company_name" />
            <asp:BoundField DataField="Company_add" HeaderText="Company_add" 
                SortExpression="Company_add" />
            <asp:BoundField DataField="Company_loc" HeaderText="Company_loc" 
                SortExpression="Company_loc" />
            <asp:BoundField DataField="State" HeaderText="State" SortExpression="State" />
            <asp:BoundField DataField="country" HeaderText="country" 
                SortExpression="country" />
            <asp:BoundField DataField="zip" HeaderText="zip" SortExpression="zip" />
            <asp:BoundField DataField="phone" HeaderText="phone" SortExpression="phone" />
            <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
            <asp:BoundField HeaderText="Site Id" ReadOnly="True" />
        </columns>
        <footerstyle backcolor="#FFFFCC" forecolor="#330099" />
        <pagerstyle backcolor="#FFFFCC" forecolor="#330099" horizontalalign="Center" />
        <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
        <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
Posted
Updated 19-Apr-15 19:04pm
v2
Comments
[no name] 20-Apr-15 1:05am    
First you check the value getting in boundvield...
Rajesh waran 20-Apr-15 1:18am    
Can you show your code for binding grid also with query? It may be useful to help you.
upendra shahi 20-Apr-15 1:31am    
Kindly show your full code..
tusharkaushik 20-Apr-15 4:04am    
this is full code

1 solution

First check weather the method is filling data table or not. Declare a debug point on line 2 of code in my case. If your DataTable is empty than it will not show you gridview.

C#
DataTable dataTable = new DataTable();
dataTable = gettingDataFromSomeMethod();

GridView1.DataSource = dataTable;
GridView1.DataBind();


One more thing you can do is give ShowHeader attribute to gridview so atleast your header will be visible inspite of, whether your datatable is empty of filled.

ASP.NET
<asp:gridview id="GridView1" runat="server" showheader="true" xmlns:asp="#unknown" />
 
Share this answer
 
v2

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