I’ve just started learning ASP.net and I can’t seem to get the GridView to correctly show itself when I compile it. Using Visual Studio ’08 in the design view, it shows it just fine, but when I compile, it’s absent.
<%@ 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>
Are you binding any data at all to the Grid? Just populate it with some data.
If there is no data nothing would show up. So, if you are using some database…like MS-SQL server…use the properties of the Grid…use the DataBinding functionality and just link it up with some table.
Now, after you compile your grid will show up with all the contents of the table in the DB ..with respective headers.