473,770 Members | 1,644 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataGrid FindControl HELP...

On my page_load, I am populating a Datagrid through the normal manner
(which works) before attempting to pick out the items in one column to
use in another part of my page. This is all within page_load.

Within my Datagrid I have an <ItemTemplate/> tag with a child
<asp:Label/> tag. The ID on the <asp:Label/> tag is set to
"lblDescription ".

I am using the following code to iterate over the DataGrid control and
pick out the descriptions I am after: This is being called AFTER the
DataBind method has been called on the DataGrid:

string productList = "";

for (int i=0; i < dataList.Items. Count; i++)
{
Label desc = (Label) dataList.Items[i].FindControl("l blDescription") ;
productList = desc.Text + ", ";
}

return productList;

However, FindControl does not seem to find the control I am after. It
always returns null.

I have used the exact same method on another page with the only
difference being I am searching for a TextBox and that works fine.

I noticed (viewing source) that on the other page that works, the id
of the text box control is rendered as an <input/> tag with the name
attribute set to "dataList:_ctl2 :txtQuantity".

The page where I want to retrieve the label, the Label control is
being rendered as a <span/> with an "id" attribute with the value
"dataList__ctl2 _lblDescription " - there is no "name" attr.

Can anyone help me. I would be most grateful if any guru out there can
shed any light on my problem.

Thanking you most kindly
Mike
Nov 18 '05 #1
1 1722
Can anyone help with this problem??? (PLEASE)

It works when searching for a TextBox within a datagrid, I assumed it
would also work for asp:Labels - but it's not...

PLEASE HELP SOMEONE :-(

mi**********@ho tmail.com (Mike Speak) wrote in message news:<dd******* *************** ****@posting.go ogle.com>...
On my page_load, I am populating a Datagrid through the normal manner
(which works) before attempting to pick out the items in one column to
use in another part of my page. This is all within page_load.

Within my Datagrid I have an <ItemTemplate/> tag with a child
<asp:Label/> tag. The ID on the <asp:Label/> tag is set to
"lblDescription ".

I am using the following code to iterate over the DataGrid control and
pick out the descriptions I am after: This is being called AFTER the
DataBind method has been called on the DataGrid:

string productList = "";

for (int i=0; i < dataList.Items. Count; i++)
{
Label desc = (Label) dataList.Items[i].FindControl("l blDescription") ;
productList = desc.Text + ", ";
}

return productList;

However, FindControl does not seem to find the control I am after. It
always returns null.

I have used the exact same method on another page with the only
difference being I am searching for a TextBox and that works fine.

I noticed (viewing source) that on the other page that works, the id
of the text box control is rendered as an <input/> tag with the name
attribute set to "dataList:_ctl2 :txtQuantity".

The page where I want to retrieve the label, the Label control is
being rendered as a <span/> with an "id" attribute with the value
"dataList__ctl2 _lblDescription " - there is no "name" attr.

Can anyone help me. I would be most grateful if any guru out there can
shed any light on my problem.

Thanking you most kindly
Mike

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2340
by: Gilles T. | last post by:
How I can get element ID in the edit mode of datagrid control? If I not in the edit mode, there are no problem. <asp:TemplateColumn ItemStyle-CssClass="grid_column_width_3" ItemStyle-HorizontalAlign="center" ItemStyle-VerticalAlign="top"> <ItemTemplate><%# CType(Container.DataItem("DateStatut"),DateTime).ToString("yyyy-MM-dd") %></ItemTemplate> <EditItemTemplate> <asp:TextBox width="80" CssClass="edit_item" id="txtDateStatut"
8
1714
by: Brent Burkart | last post by:
My datagrid OnCancelCommand event is not firing. HTML OnCancelCommand="AdminGrid_Cancel" 'Code Behind Sub AdminGrid_Cancel(ByVal sender As Object, ByVal e As DataGridCommandEventArgs) AdminGrid.EditItemIndex = -1 BindData()
1
4339
by: Rick | last post by:
Hello all, I hope all is well with you. I am having a seriously difficult time with this problem. Allow me to set up the problem. I have a System.Web.UI.Page with the following controls (watch the layout, some have child controls):
2
2394
by: Shiju Poyilil | last post by:
Hello, I have a datagrid with only one row and its having 2 dropdownlists, I need to populate the secodn dropdownlist on the basis of the selection in the first dropdown. but I am not able to populate the second dropdown, as its not bale to find the specified control, even though the dropdownlist with the specified name exists in the datagrid. my .aspx page code goes like this
9
5066
by: tshad | last post by:
How do I find (and set) a couple of labels in the Footer after a DataGrid is filled? I have a bunch of DataGrids that get displayed nested inside a DataList. The datagrid looks like: ******************************************************************************* <asp:DataGrid visible="False" border=1
10
1909
by: Terry Olsen | last post by:
I've got a datagrid set up to display data. I've also got an Edit,Update,Cancel column set up to allow editing of data. I've got a DropDownList (ID="ddl3")in the EditItemTemplate for a certain column that I need to populate while in Edit Mode. Two questions: Is there a way to directly use another DropDownList as a DataSource? If so how? I'm using the following code to try to populate the DropDownList, but
4
2280
by: steroche | last post by:
I would REALLY appreciate help please please please! Im sure it is probably blindingly obvious to most of you but I am totally in the dark here!I am lost - i thought i had finally figured out this dataSet updating lark when i realised that i think i am right back at square 1!!! Here's my scenario - i have a SQLDB and i retrieve all my data from that into a dataset and display this to a datagrid(WebForm). I have got this grid sorted and...
2
1841
by: Fabrice | last post by:
Hello, First, thanks to felix for his answer. But :-( , I'm feeling newbie :! I' don't understand all the situation. The trouble : Always in the road whith my Datagrid and my ItemTemplate with a Control HyperLink. I would like to fix many properties of this Control Hyperlink in the Code
2
12599
by: simon | last post by:
hello, new to vb.net, have a few questions about DataGrid. I have a dataGrid that is working pulling a dataset back from a stored proc and binding to the datagrid for display the datagrid's first column is a textbox(TemplateColumn), the other 3 columns are just display(BoundColumn). (1) if the value of the textbox is 0, then i'd like to change it null, so the box is empty
0
2091
by: rupalirane07 | last post by:
Both grids displays fine. But the problem is only parent datagrid sorting works fine but when i clik on child datagrid for sorting it gives me error: NullReferenceException error Any help........pls urgent ========================================================= <%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm3.aspx.vb" Inherits="TestDatagrids.WebForm3"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">...
0
10232
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10059
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10008
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
9873
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
5313
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...
0
5454
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3974
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3578
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2822
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.