473,800 Members | 2,641 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting a Value From a Datagrid

Hello,

I have the following code placed at my Page_Load event and after the
Datagrid is binded, so it is not empty. The problem is that the variable
isclass is always returning null and I am sure that the Category
ItemTemplate is there and that it is previouly populated. Am I missing
something? Here's the code:

private void Page_Load(objec t sender, System.EventArg s e)
{
if (Page.IsPostBac k == false)
{

// Calculate end-user's shopping cart ID
ShoppingCartDB cart = new ShoppingCartDB( );
String cartId = cart.GetShoppin gCartId();

// Populate datagrid with shopping cart data
MyDataGrid.Data Source = cart.GetItems(c artId);
MyDataGrid.Data Bind();

// I am trying to get the value from my ItemTemplate TextBox here:
TextBox isclass = (TextBox)MyData Grid.FindContro l("Category") ;

if (isclass.Text == "Classes" ) // I am sure this value is there - it is
not finding the control
{
cart.AddItem(ca rtId, 2, 1);
}

}
}
.....

Thanks in advance!
Nov 15 '05 #1
1 2257
Hi Juba:

If you are using an ItemTemplate in your grid, something like

<ItemTemplate >
<asp:TextBox Runat="server" id="mytextbox"> x</asp:TextBox>
</ItemTemplate>

then click View Source in IE, you'll see ASP.NET prefixed the ID of
each textbox, something like:

<input name="DataGrid1 :_ctl4:mytextbo x" type="text" value="ABBA"
id="DataGrid1__ ctl4_mytextbox" />

Basically, child controls receive a naming prefix from ASP.NET so it
will not render multiple TextBox controls all with the ID of
"Category".

What I have trouble understanding is this. If you have a DataGrid with
multiple rows, how do you know which one to pull data from? If you
have a "Selected" row , you can use FindControl on the parent of the
text box to find a value, i.e:

textbox = (TextBox)MyData Grid.SelectedIt em.FindControl( "Category") ;

Using FindControl on the DataGrid will search with the proper prefix
for the control in question.

Hope this gets you started in the right direction,

--
Scott
http://www.OdeToCode.com

On Fri, 2 Jan 2004 23:05:48 -0500, "Juba" <ju*******@hotm ail.com>
wrote:
Hello,

I have the following code placed at my Page_Load event and after the
Datagrid is binded, so it is not empty. The problem is that the variable
isclass is always returning null and I am sure that the Category
ItemTemplate is there and that it is previouly populated. Am I missing
something? Here's the code:

private void Page_Load(objec t sender, System.EventArg s e)
{
if (Page.IsPostBac k == false)
{

// Calculate end-user's shopping cart ID
ShoppingCartDB cart = new ShoppingCartDB( );
String cartId = cart.GetShoppin gCartId();

// Populate datagrid with shopping cart data
MyDataGrid.Data Source = cart.GetItems(c artId);
MyDataGrid.Data Bind();

// I am trying to get the value from my ItemTemplate TextBox here:
TextBox isclass = (TextBox)MyData Grid.FindContro l("Category") ;

if (isclass.Text == "Classes" ) // I am sure this value is there - it is
not finding the control
{
cart.AddItem(ca rtId, 2, 1);
}

}
}
....

Thanks in advance!


Nov 15 '05 #2

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

Similar topics

2
2371
by: Red Green | last post by:
I have a form with a datagrid and a dataset bound to it. I want to launch a second form and pass it a value from whichever record the user has selected. I can't find an example anywhere that shows me how to do this. I know how to launch the 2nd form and how to make a public variable to hold the value but I can't figure out how to get the value. In Delphi what I need should be something like dataSet1.FieldByName('UserID').Value; Is...
1
15753
by: Amadelle | last post by:
Hi all and thanks in advance for your help, I have a problem with capturing the changed value of a text box in a datagrid. The datagrid is populated based on a dataset and I am using template columns to show some of the columns. Few of the columns have textboxes to make them available for editing. I am trying to update the dataset all at once using one update button. Here is my code... (for simplicity I have only listed one of the...
4
3486
by: kscdavefl | last post by:
I ahve a datagrid on a web form. I need to change the value in column 3 as follows. If the value in column 3 reads 0, I want to change it to read YES. How can I accomplish this task. Thanks, Dave
3
1676
by: ALPO | last post by:
We have a datagrid built using template columns. Many are text boxes. These text boxes are bound to a datasource as follows: <ItemTemplate> <asp:TextBox id="txtPeriod1" runat="server" columns="1" Font-Size="8pt" text='<%# Container.dataitem ("LaborHoursAm")%>' >
6
1747
by: Teep | last post by:
Below is my code for dropdownlist that is populated from a SQL table. After a selection from the ddl, a datagrid is suppose to come up pertaining to the information selected, but I keep getting a DNS error. I developed this "simple" page but so far it is not simple! argh! <%@ Page Language="VB" Debug="true" Explicit="true" %> <%@ import Namespace="System.Data" %>
5
1822
by: Jason | last post by:
I've been trying to figure out a good way to do this but haven't had much luck, any input would be greatly appreciated. Basically, after a datagrid is sorted, how can I get the primary key value of the item selected by the user? That is, not the datagrid index 'location' of the item the user selected, but the value inside a column of this item the user clicked on. I would use the CurrencyManager in a windows application but I'm not...
1
2695
by: Gunjan Garg | last post by:
Hello All, I am working to create a generic datagrid which accepts a datasource(ListData - This is our own datatype) and depending on the calling program customizes itself for sorting, paginantion or accepting the add and remove item events. What i am observing is that none of the vents are happening... (Sort, page, or item). I am sure I am missing something basic here... Need help... Thanks much
2
1607
by: niceguy | last post by:
Hi I was wondering if its possible to get the exact displayed text from a cell in a datagrid. I need to get the displayed text and not any 'real' database value or anything that the cell might contain in the background. I've tried getting to get the text through the datagrid's control
1
1595
by: g.o.atkins | last post by:
Hi, I've bound an ArrayList to a datagrid and succesfully managed to display the data via an ItemTemplate column and using <%# Container.DataItem %>. The problem I have however is trying to read the value back out of the datagrid. Basically I have checkboxes next to each item in the datagrid - when the user clicks on a button im looping through each item in the datagrid and then trying to read the value out. This works for when a
0
9551
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,...
0
10504
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
9085
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...
1
7576
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
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
5469
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
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
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
3
2945
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.