Solved

Extracting information from a datagrid

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

820 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