Solved

converting gridview to listview

Posted on 2008-10-23
2
923 Views
Last Modified: 2013-12-17
Hi all, i'm trying to convert a gridview into a listview.

The bit that is troubling me is that i can't get at item.DataRowIndex ( or the list view equivilent ) on the list view

int basketItemId = (int)BasketListView.DataKeys[item].Value;

any thoughts?
// This is the grid view version
 
  foreach (GridViewRow gridRow in BasketGrid.Rows)
        {
            if ((gridRow.RowType == DataControlRowType.DataRow))
            {
                int basketItemId = (int)BasketGrid.DataKeys[gridRow.DataItemIndex].Value;
                              
 
            }
        }
 
//  What i have of the listview version
 
   foreach (ListViewItem item in BasketListView.Items)
        {
            if ((item.ItemType == ListViewItemType.DataItem))
            {
                 int basketItemId = (int)BasketListView.DataKeys[item].Value;
 
 
            }
        }

Open in new window

0
Comment
Question by:frosty1
2 Comments
 
LVL 15

Accepted Solution

by:
NazoUK earned 500 total points
ID: 22794270
There are a couple of things you could do:

1: iterate through the items using a regular for loop instead a foreach:

for(int i=0; i<BasketListView.Items.Count;i++)
{
       ListViewItem item = BasketListView.Items[i];
       if (item.ItemType == ListViewItemType.DataItem)
            {
                 int basketItemId = (int)BasketListView.DataKeys[i].Value;
            }

}

2: Use IndexOf to find the index:
int basketItemId = (int)BasketListView.DataKeys[BasketListView.Items.IndexOf(item)].Value;
0
 

Author Comment

by:frosty1
ID: 22794886
cool, thanks very useful

i also amended my for each to get ListViewDataItem

foreach (ListViewDataItem item in BasketListView.Items)
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 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