Solved

Detecting if ListViewItem or ListViewDataItem

Posted on 2011-09-15
5
1,052 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
5 Comments
 
LVL 7

Expert Comment

by:Slimfinger
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

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…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

822 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