2009-10-20 32 views
0

我剛開始學習ASP.net,我似乎無法在編譯GridView時正確顯示自己。在設計視圖中使用Visual Studio '08,它顯示它很好,但是當我編譯時,它不存在。DataGrid在設計窗口中顯示,但不在網頁中

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="WebAppTest._Default" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml" > 
<head runat="server"> 
    <title>Untitled Page</title> 
</head> 
<body> 
<form runat="server"> 
<div> 

    <asp:GridView id ="gridview1" runat ="server" AutoGenerateColumns = "False" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" > 
     <RowStyle ForeColor="#000066" /> 
     <Columns> 

      <asp:BoundField HeaderText="Test1" /> 
      <asp:BoundField HeaderText="Test2" /> 
      <asp:TemplateField HeaderText="Pick one"> 
       <ItemTemplate> 
        <asp:RadioButton ID="rbut1" runat="server" GroupName="test"/> 
       </ItemTemplate> 
       <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" /> 
      </asp:TemplateField> 

     </Columns> 
     <FooterStyle BackColor="White" ForeColor="#000066" /> 
     <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" /> 
     <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" /> 
     <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" /> 
    </asp:GridView>  

</div> 
</form> 
</body> 
</html> 
+0

你的數據源在哪裏? – 2009-10-20 02:19:29

回答

4

你是否將任何數據綁定到了網格?只需填寫一些數據即可。

如果沒有數據,則不會顯示出來。所以,如果你正在使用某個數據庫......就像MS-SQL服務器一樣......使用網格的屬性...使用DataBinding功能並將其與某個錶鏈接起來。

現在,您編譯後,您的網格將顯示與DB ..表中的所有內容..與各自的標題。

1

我沒有看到你的數據表,如果你在代碼隱藏中分配它 - 你需要DataBind()網格在頁面上看到它。

您還可以創建在設計視圖中的數據源,並將其分配給電網 - 沒有明確的數據綁定需要

0

網格顯示你已經綁定了一切,僅此而已。

1

您是否設置了gridview的數據源? 如果是,那麼將代碼粘貼到gridview中。

請確保您將gridview綁定到數據源。

相關問題