Solved

Extracting information from a datagrid

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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