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

Home Posts Topics Members FAQ

Help: How to read data from each row of a GridView?

Hi,

I have a GridView like this one:
==
<asp:gridview runat="server" id="gvCategory " allowpaging="tr ue" allowsorting="t rue"
alternatingrows tyle-backcolor="#B9D FC7" autogeneratecol umns="false"
pagesize="20" width="550px" datasourceid="p rodList">
<headerstyle backcolor="#B9D FC7" />
<columns>
<asp:templatefi eld>
<itemtemplate >
<asp:checkbox runat="server" id="chkAddToCar t" />
</itemtemplate>
</asp:templatefie ld>
<asp:boundfie ld headertext="pro ductID" datafield="prod uctID" visible="false" />
<asp:templatefi eld>
<itemtemplate >
<a href='<%# "/product/productDetail.a spx?productID="
+DataBinder.Eva l(Container.Dat aItem, "productId" ) %>'><img alt="" src='<%# "/images/prod/"
+DataBinder.Eva l(Container.Dat aItem, "thumbImg") %>' style="border:n one" /></a>
</itemtemplate>
</asp:templatefie ld>
</columns>
</asp:gridview>
==

In .Net 1.x, the DataGrid works with the following code:
==
foreach (DataGridItem dgi in DataGrid1.Items )
{
chb = (CheckBox)dgi.F indControl("chk AddToCart");
if (chb.Checked)
{
string pid=dgi.Cells[1].Text;
}
}
==

So I tried:
==
foreach (GridViewRow gvr in gvCategory.Rows )
{
if(gvr.HasContr ols()==true)
{
chb = (CheckBox)gvr.F indControl("chk AddToCart");

if (chb.Checked)
{
string pid = gvr.Cells[1].Text;
}
}
}
==
But gvr.Cells[1].Text returns nothing. What's wrong here?

Would you please tell me how to read data from the 2nd field--the Cells[1]
(i.e. <asp:boundfie ld headertext="pro ductID" datafield="prod uctID" visible="false" />)
in each row of the above GridView?

Thank you

hb
Feb 16 '06 #1
0 1451

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

Similar topics

4
2619
by: Nalaka | last post by:
Hi, I have two questions about gridViews. 1. How can I intercept the row/column values at loading to change values? 2. After I update a row (using default update functionality), how can I re-format the updated row fields. I have looked at gridView.rowUpdated method, but cannot figure out how....
2
4461
by: rufpirat | last post by:
Hello I'm in the middle of trying to build an "AD phone book", and this being my first try at asp.net, I have a few questions that I hope some of you might be able to help with: 1. Is it correct, that PageSize equals the max size of the result set? 2. Is there a way to make asp cache the search result, so the domain controller won't be to bother by all the lookups, and also to speed up
5
6455
by: sutphinwb | last post by:
Hi - This could be a simple question. When I relate two tables in a datasetet, how do I get that relation to show up in a GridView? The only way I've done it, is to create a separate table in the dataset with a join query for the GetData() select method. I use ObjectDataStore to couple the GridView with the table adapter on the dataset. If I point the ODS at the child table, the GridView will bind to the "normal" select and I end up...
0
1889
by: yeltsin27 | last post by:
I need some advice on handling dynamically added controls in a GridView. My app takes an uploaded CSV file containing addresses, converts it to a DataTable, databinds the DataTable to a GridView, accepts information via dropdowns embedded in the first row of the GridView about which incoming fields should go to which database fields, and writes the data to the database. The incoming data has an arbitrary number of columns so I create...
5
1376
by: AAJ | last post by:
Hi all FIRST THE BORING BITS....... I normally use a Database layer, a Business layer and a GUI layer. The GUI uses an Object data source to bind to the Business layer which in turn binds to the database layer. Every thing is great. I can read data, change data in the grid, update the database, and when the GUI reloads, all the changes are all present and correct. i.e. the data seems to be persisted
8
18093
by: Greg Lyles | last post by:
Hi all, I'm trying to develop an ASP.NET 2.0 website and am running into some real problems with what I thought would be a relatively simple thing to do. In a nutshell, I'm stuck on trying to display data in a "GridView" which is tied to an "ObjectDataSource". In turn, this ObjectDatasource gets it's data from a strongly-typed business object within my code.
4
3682
by: glbdev | last post by:
Hi, I posted this question yesterday but didn't get the answer I needed. I am DESPERATE to get this working so I'm re-posting it because I don't think I worded it correctly. I have a GridView which is databound to a table. All the data is being pulled correctly so there is no problem there. On each row I have an image button which is attached to a
1
1096
by: Durango2008 | last post by:
Hi, I am not sure if this is the place to seek help for my issue, but I will explain what I am stuck on. I am currently creating a page that will display data from a DB using a Gridview.(simple enough) The problem I have is that the amount of data to display is alot. The Gridview consists of 10 columns which represent the 10 fields in the DB table I pull the data from. Each piece of data is displayed in a cell, however each piece of...
0
1562
by: omgdork | last post by:
Hi! I'm having trouble on how to proceed with inserting data that are in parent and child gridviews. I have a gridview with nested gridviews that looks like this: http://img17.imageshack.us/img17/7442/nestedgridview1.jpg I could already display the gridview but the problem is storing the data. All the gridviews (parent and children) have pagers and sorting. The child gridviews are in UpdatePanels. All the checkboxes are checked by...
0
9550
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
10495
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
10269
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
10248
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
10032
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
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...
1
4148
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
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2942
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.