Solved

Extracting information from a datagrid

Posted on 2006-11-08
5
1,051 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now