Solved

converting gridview to listview

Posted on 2008-10-23
2
929 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Json and ajax 1 22
Calculating percentage 2 30
c#, datatable, aspx 4 23
write html in textarea and record it into a database table 3 13
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

733 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