Problem accessing GridView

J

Jeff

Hey

asp.net 2.0

In the source I posted below, there is a GridView (look at the bottom of the
script):
<asp:GridView ID="gvwOnline" runat="server">
</asp:GridView>

I'm trying to assign a datasource to this GridView in runtime. But I cannot
access thte GridView during runtime...
I've tryed these ways of accessing the GridView:
method 1:
TableCell tableCell = (TableCell)Table1.FindControl("TableCell1");
GridView gvwOnline = (GridView)tableCell.FindControl("gvwOnline");

method 2:
gvwOnline directly - gvwOnline.DataSource

method 3
GridView gvwOnline = (GridView)table1.FindControl("gvwOnline");

But the gvwOnline gets the value NULL from all those methods above

Any suggestions?

<asp:Table ID="Table1" runat="server" Width="100%">
<asp:TableRow>
<asp:TableCell ID="TableCell1" VerticalAlign="Top" SkinID="left" >
<div class="sidebar">
<asp:LoginView ID="LoginView2" runat="server">
<RoleGroups>
<asp:RoleGroup Roles="members">
<ContentTemplate>
<asp:LoginName ID="LoginName1" runat="server" FormatString="Welcome,
{0}." />
<asp:LoginStatus ID="LoginStatus1" runat="server"
LogoutPageUrl="../Default.aspx" />
<asp:Menu ID="mnuSidemenu" runat="server" DataSourceID="smdsHeader"
MaximumDynamicDisplayLevels="0" Orientation="Vertical"
StaticDisplayLevels="2" />
<asp:SiteMapDataSource ID="smdsHeader" runat="server"
SiteMapProvider="Members" ShowStartingNode="false" StartingNodeOffset="1" />
</ContentTemplate>
</asp:RoleGroup>
<asp:RoleGroup Roles="Administrators">
<ContentTemplate>
<asp:LoginName ID="LoginName1" runat="server" FormatString="Welcome,
{0}." />
<asp:LoginStatus ID="LoginStatus1" runat="server"
LogoutPageUrl="../Default.aspx" />
<asp:Menu ID="mnuSidemenu" runat="server" DataSourceID="smdsHeader"
MaximumDynamicDisplayLevels="0" Orientation="Vertical"
StaticDisplayLevels="2" />
<asp:SiteMapDataSource ID="smdsHeader" runat="server"
SiteMapProvider="Administrators" ShowStartingNode="false"
StartingNodeOffset="1" />
</ContentTemplate>
</asp:RoleGroup>
</RoleGroups>
<LoggedInTemplate>
<div class="sideWelcome">
<asp:LoginName ID="LoginName1" runat="server" FormatString="Welcome, {0}."
/>
<asp:LoginStatus ID="LoginStatus1" runat="server"
LogoutPageUrl="../Default.aspx" CssClass="sidemenuGeneral" />
</div>
<div class="sidepane">
<asp:Menu ID="mnuSidemenu"
runat="server"
DataSourceID="smdsHeader"
MaximumDynamicDisplayLevels="0"
Orientation="Vertical"
StaticDisplayLevels="2" StaticMenuItemStyle-CssClass="sidemenuGeneral"
StaticHoverStyle-CssClass="sidemenuHover">
</asp:Menu>
<asp:SiteMapDataSource ID="smdsHeader" runat="server"
SiteMapProvider="Members" ShowStartingNode="false" StartingNodeOffset="1" />
</div>
<div class="sidepane">
Users online<br />
<asp:GridView ID="gvwOnline" runat="server">
</asp:GridView>
</div>
</LoggedInTemplate>
</asp:LoginView>
</div>
 
S

Sean Chambers

I've never worked with the <asp:Table> controls so I'm not too sure how
these work. I would imagine they are like any other nested control
though, so I'll take a stab...

1. How many controls are within the tableCell.Controls collection? Do
you see all of the other controls in there?

2. Is there any reason in peticular that you are using the asp:Table
controls? I always just use plain old html tables, maybe I'm just old
fashioned =)... makes for less problems though (sometimes)

Where are you attempting to access the gridview from, codebehind or the
markup file? I find sometimes, I have to click between HTML/Design mode
once or twice before my codebehind shows intellisense for the control
(can't remember if that was in vs 2003 or vs 2005, i think it was vs
2005), other than that, you should be able to access the control
directly without using FindControl because your're not dynamically
adding it. kinda fishy =)

i am interested in the outcome of your problem.

Sean
 
J

Jeff

I've solved it. The reason for the error was that I've placed the GridView
inside the LoggedIn-template of the LoginView... and my code failed while
being in anonymous mode, there is no GridView in the Anonymous-template of
my LoginView
 

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

Staff online

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,072
Latest member
trafficcone

Latest Threads

Top