2010-05-06 62 views
1

數據我只是簡單地添加網格視圖以及添加列,給HEADERTEXT 但是當我運行該應用程序我不能夠看到任何網格,,至少我應該看到網格列名如何顯示從GridView的

我是否需要做的任何事情更

+0

不要忘記標記答案爲接受,如果它適合你... – 2012-06-05 05:58:50

回答

0

檢查aspx頁面代碼

<asp:MyGridView runat="server" DataKeyNames="pkey" AutoUpdateAfterCallBack="true" 
      Width="100%" 
      ID="grduser" AutoGenerateColumns="False"> 
      <Columns> 
       <asp:BoundField HeaderText="Sr No." DataField="rownumber" ReadOnly="true" HeaderStyle-Width="10px" 
        ItemStyle-Width="10px" /> 

       <asp:BoundField HeaderText="FirstName" DataField="FirstName" SortExpression="FirstName" 
        ReadOnly="true" HeaderStyle-Width="120px" ItemStyle-Width="120px" /> 
       <asp:BoundField HeaderText="LoginName" DataField="LoginName" SortExpression="LoginName" 
        ReadOnly="true" HeaderStyle-Width="120px" ItemStyle-Width="120px" /> 
       <asp:BoundField HeaderText="Email" DataField="Email" SortExpression="Email" ReadOnly="true" 
        HeaderStyle-Width="120px" ItemStyle-Width="120px" /> 
       <asp:BoundField HeaderText="Role" DataField="Role" SortExpression="Role" ReadOnly="true" 
        HeaderStyle-Width="30px" ItemStyle-Width="30px" /> 
       <asp:BoundField HeaderText="Reportingto" DataField="Reportingto" SortExpression="Reportingto" 
        ReadOnly="true" HeaderStyle-Width="120px" ItemStyle-Width="120px" /> 
       <asp:BoundField HeaderText="MobileNo" DataField="MobileNo" SortExpression="Mobile_no" 
        ReadOnly="true" HeaderStyle-Width="30px" ItemStyle-Width="30px" /> 

      </Columns> 
     </asp:MyGridView> 

銫文件代碼綁定電網

DataSet ds = new DataSet(); 
ds = //get dataset form the database 
DataView dv = new DataView(ds.Tables[0]); 
this.grduser.DataSource = dv; 
this.grdusers.DataBind(); 
1

看看確認你擁有了一切正確連接好並分配DataSource並做了DataBind()。一旦你確認了這兩件事情發生,那麼確保你的DataSource返回至少有一個項目的某種類型的結果集。

除非結果集中至少有一個項目,否則GridView將不會顯示任何內容。如果綁定到一個DataSet或某種類型的對象列表,並且其中沒有項目,則網格根本不顯示。甚至沒有標題。在這種情況下,您應該設置EmptyDataText屬性以顯示某些內容。

如果不行,如果這有幫助,請發表您的GridView標記和代碼綁定您的網格的代碼,我會看看我是否可以找出問題所在。