GridView in a table

M

mattd1

I'm using VS2008, and I need to put a gridview into a table cell (an asp
table). I made the gridview and set it all up outside the table, then I edit
the HTML and move the gridview into the table cell it should go into, but
then it doesn't show no matter what I do. It's like it's invisible. If I
drag the HTML that describes the gridview out of the table cell and on its
own, the gridview shows fine.

Is there some problem with putting a gridview in a table cell (unlikely) or
can someone tell me what the trick is?

Matt
 
M

mattd1

Hi David -

Here's the HTML. I haven't even started with the codebehind yet.

<asp:Table ID="tblSearchAndLeaseExpirations" runat="server"
Height="167px"
Width="100%" BorderColor="Black" BorderStyle="Solid"
BorderWidth="1px"
CellPadding="10" GridLines="Both">
<asp:TableRow runat="server" Width="100%">
<asp:TableCell runat="server" Width="50%" ID="tclSearch">
<asp:Table ID="tblSearchBox" runat="server"
BackColor="Cornsilk" Width="100%"
BorderColor="Black" BorderStyle="Solid"
BorderWidth="1px">

<asp:TableRow ID="TableRow1" runat="server">
<asp:TableCell ID="TableCell1" runat="server"
BackColor="CornflowerBlue" Font-Bold="True"
Font-Names="Arial" ForeColor="White">Search for
servers</asp:TableCell>
</asp:TableRow>

<asp:TableRow ID="TableRow2" runat="server">
<asp:TableCell ID="TableCell2" runat="server"
Font-Names="Tahoma" Font-Size="Smaller">Type a
server name or select one from the list. Wildcards
(* and ?) are supported</asp:TableCell>
</asp:TableRow>

<asp:TableRow ID="TableRow3" runat="server">
<asp:TableCell ID="tclErrorMessage" runat="server"
Font-Names="Tahoma" Font-Size="Smaller"
ForeColor="Red">That is not a valid server.
Please enter another name.</asp:TableCell>
</asp:TableRow>

<asp:TableRow ID="TableRow4" runat="server">
<asp:TableCell ID="TableCell4" runat="server">
<asp:TextBox ID="txtServerName" runat="server"
Width="75%">*</asp:TextBox>
</asp:TableCell>
</asp:TableRow>
</asp:Table>

<asp:Table ID="tblSearchBoxControls" runat="server"
Width="100%" BorderColor="Black"
BorderStyle="Solid" BorderWidth="1px">
<asp:TableRow ID="TableRow5" runat="server">
<asp:TableCell ID="TableCell5" runat="server"
BackColor="Cornsilk" Width="50%">
<asp:CheckBox ID="chkSearchAll" runat="server"
BackColor="Cornsilk"
Font-Names="Tahoma" Font-Size="Smaller"
Text="Search All"/>
</asp:TableCell>

<asp:TableCell ID="TableCell6" runat="server"
BackColor="Cornsilk" HorizontalAlign="Right">
<asp:Button ID="cmdGetServer" runat="server"
Font-Names="Tahoma"
Font-Size="Smaller" Text="Get Server"
Width="76" Height="21" />
</asp:TableCell>
</asp:TableRow>
</asp:Table>

</asp:TableCell>

<asp:TableCell runat="server" Width="50%"
ID="tclLeaseExpiration">
<asp:Table ID="tblLeaseExpirations" runat="server"
Height="100%" Width="100%">
<asp:TableRow runat="server" Height="20px">
<asp:TableCell runat="server"
BackColor="CornflowerBlue" Font-Names="Arial"
Font-Size="Larger" ForeColor="White">Lease
Expirations Next 90 Days
</asp:TableCell>
</asp:TableRow>

<asp:TableRow runat="server">
<asp:TableCell runat="server"
Font-Names="Arial">No servers are going end of lease in the next 90 days

<asp:GridView ID="dgData" runat="server"
AllowPaging="True"
AutoGenerateColumns="False"
EnableSortingAndPagingCallbacks="True"
Font-Names="Arial"
Font-Size="Medium" PageSize="4">
<PagerSettings Position="Top" />
<Columns>
<asp:ButtonField
DataTextField="server_name" HeaderText="Server Name"
ShowHeader="True"
Text="Button" />
<asp:BoundField
DataField="exp_lease" DataFormatString="{0:MM/dd/yyyy}"
HeaderText="Expiration" />
<asp:BoundField
DataField="status" HeaderText="Status" />
<asp:BoundField
DataField="Server_Id" HeaderText="Server Id" Visible="False" />
</Columns>
<PagerStyle
BackColor="CornflowerBlue" Font-Bold="True" Font-Names="Tahoma"
Font-Size="Small"
ForeColor="White" />
<HeaderStyle
BackColor="CornflowerBlue" Font-Names="Arial" Font-Size="Medium"
ForeColor="White" />
<AlternatingRowStyle
BackColor="Cornsilk" Font-Names="Arial"
Font-Size="Medium" />
</asp:GridView>

</asp:TableCell>
</asp:TableRow>
</asp:Table>

</asp:TableCell>
</asp:TableRow>
</asp:Table>

Thanks for taking a look

Matt

Matt-

Could you post an example of your code? As you mentioned--it should work.
I tried reproducing the code and didn't have any trouble:

aspx page:

<asp:Table ID="tbl" runat="server" GridLines="Both">
<asp:TableRow>
<asp:TableCell Text="Hello, world!" /><asp:TableCell Text="Cell 2"
/>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell ColumnSpan="2">
<p>GridView!</p>
<asp:GridView ID="gv" runat="server" />
</asp:TableCell>
</asp:TableRow>
</asp:Table>

code-behind:

protected void Page_Load(object sender, EventArgs e)
{
gv.DataSource = new NorthwindDataContext().Products.ToList();
gv.DataBind();
}

See attached image for the results.

HTH.

-dl
 
M

mattd1

So, I see the problem. I didn't realize that .net hid the grid if there was
no data. I didn't have that problem in 2005 (I'm translating the project to
2008) because I used absolute positioning instead of tables, and as I recall
the datagrid in 2005 showed regardless..

You asked a couple times about the datasource, so you were correctly focused
on the problem. Thanks a million for your help. I am moving from WinForms to
web based for this app and I don't know all these webby quirks.

Thanks again David. You were very helpful.

Matt

Matt-

I copied the HTML you have below into a new aspx page, loaded up Northwind
and picked out some similar data fields to yours, and it worked like a
champ.

I've attached an image of the results and a text file with the code I used
to generate it (I had to change a few of the Ids when they copied over as
the copy process plugged in Ids for your TableCells that didn't have them
and duplicates cropped up).

Code behind:

protected void Page_Load(object sender, EventArgs e)
{
dgData.DataSource =
new NorthwindDataContext()
.Products
.Select(x => new { x.ProductID, x.ProductName,
x.Discontinued });
dgData.DataBind();
}

How are you loading data into your grid view? Code-behind? DataSource
control?

-dl
 
M

mattd1

And the other thing that was confusing is when you are editing the page in
the page designer the gridview I don't have in a table shows up, but the one
I did have in the grid didn't show. That really confused me. Then when I run
the app I don't load any data into the grid not in the table and that one
disappears during runtime.

Confusing

Matt
 
D

David R. Longnecker

Good to hear you worked it out. I'd recommend tossing a EmptyDataTemplate
into your GridView--just for such an occassion.

<asp:GridView ...stuff here>

<EmptyDataTemplate>Sorry, no data here!</EmptyDataTemplate>

</asp:GridView>

That way, when it's empty, it'll spit that text out instead.

Now, AFAIK, it's not "hiding" the GridView, it's being extremely percise--since
the designer doesn't have a data source to render columns off of (since we're
loading data in code-behind), it assumes that there isn't any data. I'm
honestly not sure if that's a different action that in 2005 or 2003--I don't
think so. Unfortunately, I tend to stick to Source or code-behind view,
so quirks in the Designer go right over my head.

Addressing your other question (in the other thread):

This may be caused by using the asp:Table... is there a reason for using
a .NET control rather than just HTML? asp:Table generates HTML, but, at
least when I go into the designer, I can't manipulate controls inside the
TableCell(s). Using standard HTML, you should be able to drop/drag and manage
the controls inside.

Another here probably has more experience with that control and can provide
some insight--it may be behavior by design.

HTH.

-dl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top