Solved

Detecting if ListViewItem or ListViewDataItem

Posted on 2011-09-15
5
1,055 Views
Last Modified: 2012-05-12
Hi

I have a Web User Control with a DropDownList and i have a parent page with a ListView which contains the Web User Control in the InsertItem and in the EditItem

And when i use the SelectedIndexChanged and use the sender object to tell where the Control Was sent from

DropDownList DropDownList1 = (DropDownList)sender;

I then assign it to the LIistViewDataItem

        ListViewDataItem ListView1 = (ListViewDataItem)DropDownList1.Parent.Parent;

If the DropDownList is being executed in the InsertItem of the ListView then it is coming through as ListViewItem but if it is being Executed in the EditItem It is coming thorgh as a ListViewDataItem

So this is where i'm getting an error and i need a way to test which one is coming through.

Sort of Like

If (lvAssets.Item == ListViewDataItem)
 Do Something;
else if (lvAssets.Item == ListViewItem)
 Do Something;

Is this Possible?


Thanks
John

0
Comment
Question by:johngrant_ks
[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
5 Comments
 
LVL 7

Expert Comment

by:Bill Nolan
ID: 36547151
Not sure if I understand your question, but maybe this is what you want

if (lvAssets.Item.GetType() == typeof(ListViewDataItem))
0
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 36547233
Yes. You can verify the type of it using is operator.

If (lvAssets.Item is ListViewDataItem)
 Do Something;
else if (lvAssets.Item is ListViewItem)
 Do Something;
0
 
LVL 17

Expert Comment

by:sonawanekiran
ID: 36547396
OR
if (lvAssets.Item.ItemType == ListViewItemType.DataItem)
//your code
else if (lvAssets.Item.ItemType == ListViewItemType.ViewItem)
// your code
0
 
LVL 4

Accepted Solution

by:
guramrit earned 500 total points
ID: 36547535
ListViewDataItem is inheritted from ListViewItem. You can code as follows:

 
DropDownList DropDownList1 = (DropDownList)sender;
ListViewItem lvi = (ListViewItem)DropDownList1.Parent.Parent;

if (lvi is ListViewDataItem)
{
   // Do Something
}
else 
{
   // Do Something
}

Open in new window

0
 

Author Closing Comment

by:johngrant_ks
ID: 36557653
Hi

USing your suggestion ii found i didnt need to detect if it was a dataitem or just an item

I could just do

 DropDownList DropDownList1 = (DropDownList)sender;
        ListViewItem ListViewItem1 = (ListViewItem)DropDownList1 .Parent.Parent;

And it worked

Thank you all for your help
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

749 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