Solved

Detecting if ListViewItem or ListViewDataItem

Posted on 2011-09-15
5
1,044 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now