By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,561 Members | 3,221 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,561 IT Pros & Developers. It's quick & easy.

Problem accessing GridView

P: n/a
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>
Oct 11 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
I've never worked with the <asp:Tablecontrols 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
Jeff wrote:
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>
Oct 11 '06 #2

P: n/a
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
"Sean Chambers" <dk****@gmail.comwrote in message
news:11**********************@c28g2000cwb.googlegr oups.com...
I've never worked with the <asp:Tablecontrols 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
Jeff wrote:
>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>

Oct 11 '06 #3

P: n/a
ahh,

I can't believe I missed that. Good job!

Cheers!

Sean

Jeff wrote:
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
"Sean Chambers" <dk****@gmail.comwrote in message
news:11**********************@c28g2000cwb.googlegr oups.com...
I've never worked with the <asp:Tablecontrols 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
Jeff wrote:
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>
Oct 11 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.