Solved

Extracting information from a datagrid

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
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 …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

706 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

21 Experts available now in Live!

Get 1:1 Help Now