Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
My grid view isn't displayed any row even if the i specify ShowHeaderWhenEmpty="true" and "EmptyDataTemplate" under the gridview tag:
XML
<asp:GridView ID="GridView1" runat="Server" AutoGenerateColumns="False" BorderWidth="1"
        DataKeyNames="AutoID" AutoGenerateEditButton="True" OnRowEditing="EditRecord"
        OnRowCancelingEdit="CancelRecord" OnRowUpdating="UpdateRecord" CellPadding="4"
        HeaderStyle-HorizontalAlign="left" OnRowDeleting="DeleteRecord" RowStyle-VerticalAlign="Top"
        ForeColor="#333333" GridLines="None" ShowHeaderWhenEmpty="true">
        <EmptyDataTemplate>
            <asp:Label ID="norecord" Text="no data was found" runat="server"></asp:Label>
        </EmptyDataTemplate>
        <Columns>
            <asp:BoundField DataField="AutoID" HeaderText="AutoID" />
            <asp:TemplateField HeaderText="Page Name">
                <ItemTemplate>
                    <%# Eval("PageName") %>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtPageName" runat="Server" Text='<%# Eval("PageName") %>' Columns="30"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="req1" runat="Server" Text="*" ControlToValidate="txtPageName"></asp:RequiredFieldValidator>
                </EditItemTemplate>
            </asp:TemplateField>
           
        </Columns>
        <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
        <RowStyle BackColor="#FFFBD6" ForeColor="#333333" VerticalAlign="Top" />
        <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
        <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
        <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" HorizontalAlign="Left" />
        <AlternatingRowStyle BackColor="White" />

    </asp:GridView>

and this is my code behind
VB
Imports System.Data.SqlClient

Public Class _Default
    Inherits System.Web.UI.Page
    Dim connStr As String = ConfigurationManager.ConnectionStrings("Cstring").ToString
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        BindData()
    End Sub

    ''' <summary>
    ''' Bind data to the grid
    ''' </summary>
    Private Sub BindData()
        Dim conn As SqlConnection = New SqlConnection(connStr)
        Dim dAd As SqlDataAdapter = New SqlDataAdapter("select * from Page", conn)
        Dim dSet As DataSet = New DataSet
        Try
            dAd.Fill(dSet)
            GridView1.DataSource = dSet
            GridView1.DataBind()
        Catch ee As Exception
            lblMessage.Text = ee.Message.ToString
        Finally
            dSet.Dispose()
            dAd.Dispose()
            conn.Close()
            conn.Dispose()
        End Try
    End Sub   
    End Class

and finaly the web.config

XML
<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
  <connectionStrings>
    <add name="Cstring"
         connectionString="data source=.\SQLEXPRESS;Integrated Security=sspi;Database=Test;"
         providerName="System.Data.SqlClient" />
  </connectionStrings>

 </configuration>
Posted

1 solution

try to change:

GridView1.DataSource = dSet


by

GridView1.DataSource = dSet.Tables(0)


or test gridview by using auto generation, than turn it false

AutoGenerateColumns="False" 
to
AutoGenerateColumns="True"
 
Share this answer
 
Comments
Sandeep Mewara 9-Jun-12 13:19pm    
5!

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