2017-07-03 138 views
0

我當前已創建一個數據視圖,用戶網絡控制它 目前這是在GridView一個佔位符內的GridView

<div class="col-md-12"> 
     <asp:GridView id="dtgrid1" runat="server" AutoGenerateColumns="False" AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" AutoGenerateSelectButton="True" CellPadding="4" ForeColor="#333333" GridLines="Horizontal" AllowPaging="True" width="100%" ShowFooter="True" ShowHeaderWhenEmpty="True" EmptyDataText="No records Found"> 
      <AlternatingRowStyle BackColor="White" ForeColor="#284775" /> 
      <Columns> 
       <asp:BoundField DataField="ID" HeaderText="ID" ItemStyle-Width="30" /> 
       <asp:BoundField DataField="Descripcion" HeaderText="Descripcion" ItemStyle-Width="250" /> 
       <asp:BoundField DataField="Monto" HeaderText="Monto" ItemStyle-Width="150" /> 
       <asp:BoundField DataField="Fecha" HeaderText="Fecha" ItemStyle-Width="150" /> 
      </Columns> 
      <EditRowStyle BackColor="#999999" /> 
      <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> 
      <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> 
      <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /> 
      <RowStyle BackColor="#F7F6F3" ForeColor="#333333" /> 
      <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /> 
      <SortedAscendingCellStyle BackColor="#E9E7E2" /> 
      <SortedAscendingHeaderStyle BackColor="#506C8C" /> 
      <SortedDescendingCellStyle BackColor="#FFFDF8" /> 
      <SortedDescendingHeaderStyle BackColor="#6F8DAE" /> 
     </asp:GridView> 
    </div> 

是GridView控件與其他cotrols和div的一個WEBUSER控制,萬物顯示爲它應該,但在GridView的 這是對onload事件

If Not Page.IsPostBack Then 
      dim dgv1datatable as new DataTable 
      With dgv1datatable 
       .Columns.Add(New DataColumn("ID", GetType(Integer))) 
       .Columns.Add(New DataColumn("Descripcion", GetType(String))) 
       .Columns.Add(New DataColumn("Monto", GetType(Double))) 
       .Columns.Add(New DataColumn("Fecha", GetType(Date))) 
      End With 
      Session("dgv1dt") = dgv1datatable 
      dtgrid1.DataSource = DirectCast(Session("dgv1dt"), DataTable) 
      dtgrid1.DataBind() 
      dtgrid1.Visible = True 
     End If 

但它現在顯示在GridView但代碼,如果我insted的地方gridview的其中佔位符應該是在GridView顯示有任何幫助嗎?

編輯 我去嘗試,並更好地解釋這個問題 這是在GridView的應在webusercontrol這是一個佔位符 enter image description here 如此,因爲它並沒有顯示我決定刪除佔位符和地點內已經在同一個地方的GridView和它沒有出現 enter image description here

+0

你的數據表上從來沒有加載任何數據,你怎麼能指望任何東西展現出來呢? – Andrei

+1

在另一個筆記上,請不要將數據表存儲到會話中 – Andrei

+0

好吧,假設數據庫未加載是問題,它應該至少說當我將gridview放到網站中時發生的「沒有記錄」消息self而不是webusercontrol – ZStinger

回答

0
<asp:SqlDataSource ID="SqlDataSource1" runat="server" CacheExpirationPolicy="Sliding" 
    ConnectionString="<%$ ConnectionStrings:catalog %>"  
     SelectCommand="SELECT * FROM YourDB"></asp:SqlDataSource> 
+0

在您的代碼中留下評論以供將來理解 – AsifAli72090

+0

我希望gridview爲空,因爲用戶將填充它 – ZStinger