views:

46

answers:

4

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"&gt;

<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>
+4  A: 

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.

Shankar Ramachandran
+1  A: 

I don't see your datasouce, if you assigning it in the code-behind - you need to DataBind() the grid to see it on the page.

You can also create a datasource in the design view, and assign it to the grid - no explicit databinding needed

roman m
A: 

The Grid is showing everything you have bound to it, and nothing more.

Chris Ballance
+1  A: 

Have you set the datasource for the gridview? If yes then post the code where u r binding the gridview.

Please make sure you bind the gridview with datasource.

Himadri