Henz D'Wraith
Henz D'Wraith

Reputation: 93

ASP.NET GridView cant display in page load

I have problem in display gridview in my project asp.net . This is my Gridview.

            <asp:GridView ID="GridView1" runat="server" Width="100%"  ViewStateMode="Enabled" AutoGenerateColumns="true" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal" AutoGenerateSelectButton="true" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
                <AlternatingRowStyle BackColor="#F7F7F7" />
                <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
                <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
                <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
                <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
                <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
                <SortedAscendingCellStyle BackColor="#F4F4FD" />
                <SortedAscendingHeaderStyle BackColor="#5A4C9D" />
                <SortedDescendingCellStyle BackColor="#D8D8F0" />
                <SortedDescendingHeaderStyle BackColor="#3E3277" />
            </asp:GridView>

This is my code in page load.

protected void Page_Load(object sender, EventArgs e)
{
    try
    {
        OracleConnection conn = new OracleConnection();
        conn.ConnectionString = connectionstring;
        conn.Open();
        string sql = "select * from merchant";
        OracleCommand cmd = new OracleCommand(sql, conn);
        OracleDataAdapter da = new OracleDataAdapter(cmd);
        DataTable dt = new DataTable();
        da.Fill(dt);
        GridView1.DataSource = dt;
        GridView1.DataBind();
        conn.Close();
    }
    catch (Exception ex)
    {
        Response.Write("Error : " + ex.ToString());
        Label1.Text = ex.ToString();
    }
}

why my Gridview can't display?. Someone please fix my problem. Thanks

Upvotes: 0

Views: 589

Answers (1)

Daniel Pato
Daniel Pato

Reputation: 26

Change Your ASP.NET CODE Exp:

<asp:GridView ID="gvUsers" runat="server" AutoGenerateColumns="false">
    <Columns>
        <asp:BoundField HeaderText="ID" DataField="IDUser" ItemStyle-Width="50"/>
        <asp:BoundField HeaderText="Name" DataField="Name" ItemStyle-Width="200"/>
        <asp:BoundField HeaderText="Username" DataField="UserName" ItemStyle-Width="200"/>
    </Columns>
</asp:GridView>

Upvotes: 1

Related Questions