Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Detecting if ListViewItem or ListViewDataItem

Posted on 2011-09-15
5
Medium Priority
?
1,088 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 2000 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

Industry Leaders: 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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

636 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