473,507 Members | 8,054 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem accessing GridView

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
3 4590
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2675
by: hazz | last post by:
A treeview control should be able to select various aspx pages in the site. (using sitemap) One content page will have a gridview, accessed through a content place holder while another aspx page...
0
1647
by: Dom | last post by:
Hello This should work I know ... but.. with your help perhaps.. Trying to assign a 'selectparameter' to an objectdatasource nested within a gridview EditItemTemplate. When I try to access...
0
1215
by: Mudassar | last post by:
I am facing a problem while accessing the gridview in nested gridview structure. Some time i found child gridview control but when i bind data to child gridview it doesnt
3
1764
by: John | last post by:
Hi I have a hidden (visible=false) column on a gridview bound to a sql server table. I am trying to access the field as; For Each row As GridViewRow In grdEvents.Rows If row.RowType =...
1
2265
by: parshuram | last post by:
I am having a gridview accessing 'objectDataSource1' which inturn is connected to data addapter. The dataadapter is having a select function getmydata1(int32 eid,String edesc) which is having a...
6
17888
by: Greg | last post by:
Hello, I have a GridView bound to a custom object. I set the DataKeyNames property along with the column DataField properties at design time, and bind the GridView to my object at run-time. In...
2
1100
by: jph | last post by:
Hello, im starting asp.net coder, just doing my first asp.net test site. Im having problems accessing gridview's autogenerated edit,update, cancel text properties. Gridview itself works fine, i...
1
4672
by: HockeyFan | last post by:
protected void gvAuthorizedSigners_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "EmptyInsert") { odsAuthorizedSigners.Insert(); return; } if (e.CommandName...
0
1201
by: damnBoi | last post by:
Good day guys! I'm using c# as my code-behind (ascx.cs) and my environment is Visual Studio 2008. the issue is, i can't get to access labels inside the gridview.. my gridview definition is:...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
7030
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7482
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5041
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.