简体   繁体   English

ASP.NET GridView无法在页面加载中显示

[英]ASP.NET GridView cant display in page load

I have problem in display gridview in my project asp.net . 我在asp.net项目中显示gridview时遇到问题。 This is my Gridview. 这是我的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?. 为什么我的Gridview无法显示? Someone please fix my problem. 有人请解决我的问题。 Thanks 谢谢

Change Your ASP.NET CODE Exp: 更改您的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> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM