473,698 Members | 2,213 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)Tabl e1.FindControl( "TableCell1 ");
GridView gvwOnline = (GridView)table Cell.FindContro l("gvwOnline" );

method 2:
gvwOnline directly - gvwOnline.DataS ource

method 3
GridView gvwOnline = (GridView)table 1.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:TableCel l ID="TableCell1 " VerticalAlign=" Top" SkinID="left" >
<div class="sidebar" >
<asp:LoginVie w ID="LoginView2 " runat="server">
<RoleGroups>
<asp:RoleGrou p Roles="members" >
<ContentTemplat e>
<asp:LoginNam e ID="LoginName1 " runat="server" FormatString="W elcome,
{0}." />
<asp:LoginStatu s ID="LoginStatus 1" runat="server"
LogoutPageUrl=" ../Default.aspx" />
<asp:Menu ID="mnuSidemenu " runat="server" DataSourceID="s mdsHeader"
MaximumDynamicD isplayLevels="0 " Orientation="Ve rtical"
StaticDisplayLe vels="2" />
<asp:SiteMapDat aSource ID="smdsHeader " runat="server"
SiteMapProvider ="Members" ShowStartingNod e="false" StartingNodeOff set="1" />
</ContentTemplate >
</asp:RoleGroup>
<asp:RoleGrou p Roles="Administ rators">
<ContentTemplat e>
<asp:LoginNam e ID="LoginName1 " runat="server" FormatString="W elcome,
{0}." />
<asp:LoginStatu s ID="LoginStatus 1" runat="server"
LogoutPageUrl=" ../Default.aspx" />
<asp:Menu ID="mnuSidemenu " runat="server" DataSourceID="s mdsHeader"
MaximumDynamicD isplayLevels="0 " Orientation="Ve rtical"
StaticDisplayLe vels="2" />
<asp:SiteMapDat aSource ID="smdsHeader " runat="server"
SiteMapProvider ="Administrator s" ShowStartingNod e="false"
StartingNodeOff set="1" />
</ContentTemplate >
</asp:RoleGroup>
</RoleGroups>
<LoggedInTempla te>
<div class="sideWelc ome">
<asp:LoginNam e ID="LoginName1 " runat="server" FormatString="W elcome, {0}."
/>
<asp:LoginStatu s ID="LoginStatus 1" runat="server"
LogoutPageUrl=" ../Default.aspx" CssClass="sidem enuGeneral" />
</div>
<div class="sidepane ">
<asp:Menu ID="mnuSidemenu "
runat="server"
DataSourceID="s mdsHeader"
MaximumDynamicD isplayLevels="0 "
Orientation="Ve rtical"
StaticDisplayLe vels="2" StaticMenuItemS tyle-CssClass="sidem enuGeneral"
StaticHoverStyl e-CssClass="sidem enuHover">
</asp:Menu>
<asp:SiteMapDat aSource ID="smdsHeader " runat="server"
SiteMapProvider ="Members" ShowStartingNod e="false" StartingNodeOff set="1" />
</div>
<div class="sidepane ">
Users online<br />
<asp:GridView ID="gvwOnline" runat="server">
</asp:GridView>
</div>
</LoggedInTemplat e>
</asp:LoginView>
</div>
Oct 11 '06 #1
3 4600
I've never worked with the <asp:Tablecontr ols 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.Contr ols 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)Tabl e1.FindControl( "TableCell1 ");
GridView gvwOnline = (GridView)table Cell.FindContro l("gvwOnline" );

method 2:
gvwOnline directly - gvwOnline.DataS ource

method 3
GridView gvwOnline = (GridView)table 1.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:TableCel l ID="TableCell1 " VerticalAlign=" Top" SkinID="left" >
<div class="sidebar" >
<asp:LoginVie w ID="LoginView2 " runat="server">
<RoleGroups>
<asp:RoleGrou p Roles="members" >
<ContentTemplat e>
<asp:LoginNam e ID="LoginName1 " runat="server" FormatString="W elcome,
{0}." />
<asp:LoginStatu s ID="LoginStatus 1" runat="server"
LogoutPageUrl=" ../Default.aspx" />
<asp:Menu ID="mnuSidemenu " runat="server" DataSourceID="s mdsHeader"
MaximumDynamicD isplayLevels="0 " Orientation="Ve rtical"
StaticDisplayLe vels="2" />
<asp:SiteMapDat aSource ID="smdsHeader " runat="server"
SiteMapProvider ="Members" ShowStartingNod e="false" StartingNodeOff set="1" />
</ContentTemplate >
</asp:RoleGroup>
<asp:RoleGrou p Roles="Administ rators">
<ContentTemplat e>
<asp:LoginNam e ID="LoginName1 " runat="server" FormatString="W elcome,
{0}." />
<asp:LoginStatu s ID="LoginStatus 1" runat="server"
LogoutPageUrl=" ../Default.aspx" />
<asp:Menu ID="mnuSidemenu " runat="server" DataSourceID="s mdsHeader"
MaximumDynamicD isplayLevels="0 " Orientation="Ve rtical"
StaticDisplayLe vels="2" />
<asp:SiteMapDat aSource ID="smdsHeader " runat="server"
SiteMapProvider ="Administrator s" ShowStartingNod e="false"
StartingNodeOff set="1" />
</ContentTemplate >
</asp:RoleGroup>
</RoleGroups>
<LoggedInTempla te>
<div class="sideWelc ome">
<asp:LoginNam e ID="LoginName1 " runat="server" FormatString="W elcome, {0}."
/>
<asp:LoginStatu s ID="LoginStatus 1" runat="server"
LogoutPageUrl=" ../Default.aspx" CssClass="sidem enuGeneral" />
</div>
<div class="sidepane ">
<asp:Menu ID="mnuSidemenu "
runat="server"
DataSourceID="s mdsHeader"
MaximumDynamicD isplayLevels="0 "
Orientation="Ve rtical"
StaticDisplayLe vels="2" StaticMenuItemS tyle-CssClass="sidem enuGeneral"
StaticHoverStyl e-CssClass="sidem enuHover">
</asp:Menu>
<asp:SiteMapDat aSource ID="smdsHeader " runat="server"
SiteMapProvider ="Members" ShowStartingNod e="false" StartingNodeOff set="1" />
</div>
<div class="sidepane ">
Users online<br />
<asp:GridView ID="gvwOnline" runat="server">
</asp:GridView>
</div>
</LoggedInTemplat e>
</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.c omwrote in message
news:11******** **************@ c28g2000cwb.goo glegroups.com.. .
I've never worked with the <asp:Tablecontr ols 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.Contr ols 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:GridVie w 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)Tabl e1.FindControl( "TableCell1 ");
GridView gvwOnline = (GridView)table Cell.FindContro l("gvwOnline" );

method 2:
gvwOnline directly - gvwOnline.DataS ource

method 3
GridView gvwOnline = (GridView)table 1.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:TableRo w>
<asp:TableCe ll ID="TableCell1 " VerticalAlign=" Top" SkinID="left" >
<div class="sidebar" >
<asp:LoginVie w ID="LoginView2 " runat="server">
<RoleGroups>
<asp:RoleGrou p Roles="members" >
<ContentTemplat e>
<asp:LoginNam e ID="LoginName1 " runat="server" FormatString="W elcome,
{0}." />
<asp:LoginStatu s ID="LoginStatus 1" runat="server"
LogoutPageUrl= "../Default.aspx" />
<asp:Menu ID="mnuSidemenu " runat="server" DataSourceID="s mdsHeader"
MaximumDynamic DisplayLevels=" 0" Orientation="Ve rtical"
StaticDisplayL evels="2" />
<asp:SiteMapDat aSource ID="smdsHeader " runat="server"
SiteMapProvide r="Members" ShowStartingNod e="false" StartingNodeOff set="1"
/>
</ContentTemplate >
</asp:RoleGroup>
<asp:RoleGrou p Roles="Administ rators">
<ContentTemplat e>
<asp:LoginNam e ID="LoginName1 " runat="server"
FormatString=" Welcome,
{0}." />
<asp:LoginStatu s ID="LoginStatus 1" runat="server"
LogoutPageUrl= "../Default.aspx" />
<asp:Menu ID="mnuSidemenu " runat="server" DataSourceID="s mdsHeader"
MaximumDynamic DisplayLevels=" 0" Orientation="Ve rtical"
StaticDisplayL evels="2" />
<asp:SiteMapDat aSource ID="smdsHeader " runat="server"
SiteMapProvide r="Administrato rs" ShowStartingNod e="false"
StartingNodeOf fset="1" />
</ContentTemplate >
</asp:RoleGroup>
</RoleGroups>
<LoggedInTempla te>
<div class="sideWelc ome">
<asp:LoginNam e ID="LoginName1 " runat="server" FormatString="W elcome,
{0}."
/>
<asp:LoginStatu s ID="LoginStatus 1" runat="server"
LogoutPageUrl= "../Default.aspx" CssClass="sidem enuGeneral" />
</div>
<div class="sidepane ">
<asp:Menu ID="mnuSidemenu "
runat="server"
DataSourceID="s mdsHeader"
MaximumDynamicD isplayLevels="0 "
Orientation="Ve rtical"
StaticDisplayLe vels="2"
StaticMenuItem Style-CssClass="sidem enuGeneral"
StaticHoverStyl e-CssClass="sidem enuHover">
</asp:Menu>
<asp:SiteMapDat aSource ID="smdsHeader " runat="server"
SiteMapProvide r="Members" ShowStartingNod e="false" StartingNodeOff set="1"
/>
</div>
<div class="sidepane ">
Users online<br />
<asp:GridView ID="gvwOnline" runat="server">
</asp:GridView>
</div>
</LoggedInTemplat e>
</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.c omwrote in message
news:11******** **************@ c28g2000cwb.goo glegroups.com.. .
I've never worked with the <asp:Tablecontr ols 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.Contr ols 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)Tabl e1.FindControl( "TableCell1 ");
GridView gvwOnline = (GridView)table Cell.FindContro l("gvwOnline" );

method 2:
gvwOnline directly - gvwOnline.DataS ource

method 3
GridView gvwOnline = (GridView)table 1.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:TableCel l ID="TableCell1 " VerticalAlign=" Top" SkinID="left" >
<div class="sidebar" >
<asp:LoginVie w ID="LoginView2 " runat="server">
<RoleGroups>
<asp:RoleGrou p Roles="members" >
<ContentTemplat e>
<asp:LoginNam e ID="LoginName1 " runat="server" FormatString="W elcome,
{0}." />
<asp:LoginStatu s ID="LoginStatus 1" runat="server"
LogoutPageUrl=" ../Default.aspx" />
<asp:Menu ID="mnuSidemenu " runat="server" DataSourceID="s mdsHeader"
MaximumDynamicD isplayLevels="0 " Orientation="Ve rtical"
StaticDisplayLe vels="2" />
<asp:SiteMapDat aSource ID="smdsHeader " runat="server"
SiteMapProvider ="Members" ShowStartingNod e="false" StartingNodeOff set="1"
/>
</ContentTemplate >
</asp:RoleGroup>
<asp:RoleGrou p Roles="Administ rators">
<ContentTemplat e>
<asp:LoginNam e ID="LoginName1 " runat="server"
FormatString="W elcome,
{0}." />
<asp:LoginStatu s ID="LoginStatus 1" runat="server"
LogoutPageUrl=" ../Default.aspx" />
<asp:Menu ID="mnuSidemenu " runat="server" DataSourceID="s mdsHeader"
MaximumDynamicD isplayLevels="0 " Orientation="Ve rtical"
StaticDisplayLe vels="2" />
<asp:SiteMapDat aSource ID="smdsHeader " runat="server"
SiteMapProvider ="Administrator s" ShowStartingNod e="false"
StartingNodeOff set="1" />
</ContentTemplate >
</asp:RoleGroup>
</RoleGroups>
<LoggedInTempla te>
<div class="sideWelc ome">
<asp:LoginNam e ID="LoginName1 " runat="server" FormatString="W elcome,
{0}."
/>
<asp:LoginStatu s ID="LoginStatus 1" runat="server"
LogoutPageUrl=" ../Default.aspx" CssClass="sidem enuGeneral" />
</div>
<div class="sidepane ">
<asp:Menu ID="mnuSidemenu "
runat="server"
DataSourceID="s mdsHeader"
MaximumDynamicD isplayLevels="0 "
Orientation="Ve rtical"
StaticDisplayLe vels="2"
StaticMenuItemS tyle-CssClass="sidem enuGeneral"
StaticHoverStyl e-CssClass="sidem enuHover">
</asp:Menu>
<asp:SiteMapDat aSource ID="smdsHeader " runat="server"
SiteMapProvider ="Members" ShowStartingNod e="false" StartingNodeOff set="1"
/>
</div>
<div class="sidepane ">
Users online<br />
<asp:GridView ID="gvwOnline" runat="server">
</asp:GridView>
</div>
</LoggedInTemplat e>
</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
2681
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 will contain a report viewer, accessed through the same contentplaceholder. At least that is how I understand it. If I want the master page to contain a button to create an excel file from the gridview contents, how do I access the gridview on...
0
1651
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 access the object in the OnRowDataBound event am getting a null
0
1221
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
1773
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 = DataControlRowType.DataRow Then bf = CType(row.Cells(row.Cells.Count - 1).FindControl("event id"), BoundField) End if
1
2275
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 select statement."SELECT .....FROM mytable where (@eid ='' or eid = @eid) and(@edesc ='' or @edesc=edesc)" I am able to show all the records in my form(with in the gridview) at the first time. In the same form I am having 2 text boxes which...
6
17898
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 the RowDeleting event, I try to access the DataKeys property, but it contains no elements. This is the first time I'm trying to use DatKeyNames and DataKeys. What am I missing here?
2
1108
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 just need to change captions in code. I cant do it on gridviews properties as in my site i have language option, so i must change those captions by wich ever language user has chosen. This may be just simple property i have missed but spent last...
1
4684
by: HockeyFan | last post by:
protected void gvAuthorizedSigners_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "EmptyInsert") { odsAuthorizedSigners.Insert(); return; } if (e.CommandName == "Insert")
0
1213
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
8673
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8601
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8892
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8860
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7716
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5860
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4365
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2327
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1998
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.