Solved

Extracting information from a datagrid

Posted on 2006-11-08
5
1,075 Views
Last Modified: 2012-06-27
Okay, hopefully someone can help, because I am out of ideas and will be out of time relatively soon...

I'm building a web app using asp.net 2.0. I am trying to pull information from a datagrid to populate different dropdown lists and text fields on the page. I looked at some of the other discussions, and nothing worked. I tried to do datagrid.items(1,2), but didn't have the option to do a .items immediately afer my datagrid. I tried datagrid.columns(2), datagrid.columns.item(2) and on and on and on, but nothing worked right. The only value it was pulling was the column header, not the actual value. Every time I tried to do something with a row, it would say the index was out of range. I also tried the .extractvaluesfromcell, but that just confused me even more. Please help!
0
Comment
Question by:daugh016
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 12

Accepted Solution

by:
sandip132 earned 500 total points
ID: 17904225
Here is my code using to get row values from a datagrid:

        // Iterate through all rows within shopping cart list
        for (int i=0; i < MyList.Items.Count; i++) {
   
            // Obtain references to rows controls
            TextBox quantityTxt = (TextBox) MyList.Items[i].FindControl("Quantity");
            CheckBox remove = (CheckBox) MyList.Items[i].FindControl("Remove");
   
            // Wrap in try/catch block to catch errors in the event that someone types in
            // an invalid value for quantity
            int quantity;
            try {
                quantity = Int32.Parse(quantityTxt.Text);
   
                // If the quantity field is changed or delete is checked
                if (quantity != (int)MyList.DataKeys[i] || remove.Checked == true) {
   
                    Label lblProductID = (Label) MyList.Items[i].FindControl("ProductID");
   
                    if (quantity == 0 || remove.Checked == true) {
                        cart.RemoveItem(cartId, Int32.Parse(lblProductID.Text));
                    }
                    else {
                        cart.UpdateItem(cartId, Int32.Parse(lblProductID.Text),quantity);
                    }
                }
            }
            catch {
                MyError.Text = "There has been a problem with one or more of your inputs.";
            }
        }
0
 

Author Comment

by:daugh016
ID: 17908880
Sorry, I didn't mention that I was using vb. :) Thanks, though.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question