2016-05-12 104 views
0

我在我的asp.net项目中显示gridview时遇到问题。 这是我的Gridview。ASP.NET 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> 

这是我的页面加载中的代码。

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(); 
    } 
} 

为什么我的Gridview无法显示?有人请解决我的问题。 感谢

+0

你调试?你从数据库中获取数据吗? –

+0

我已经调试过了。从数据库中获取数据。但gridview不显示在浏览器 –

+1

据我所知你的gridview是完美的,你只需检查你的Dataadapter和数据源。你是否得到任何运行时异常?或只加载空白页面? –

回答

1

改变你的ASP.NET代码 经验:

<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>