Solved

Need ASP.NET ListView to fire SelectedIndex events

Posted on 2009-05-06
8
1,699 Views
Last Modified: 2012-05-06
Hello!

I have a ListView that is DataBound in the Code Behind (any language).  The first 'column' is a RadioButton.  I'm able to handle the CheckedChange so that the first column performs like a RadioButtonList, BUT, in that event changing the SelectedIndex of the ListView only works on the initial page load.

My ultimate goal is to have the SelectedIndex be correct when the RadioButton is checked/changed, but the only way I can get the ListView's OnSelectedIndexChanged event to fire is to add a LinkButton and set the CommandName.

I'm up against a deadline today and am turning here as a last resort.  I'll be 'closing' this question before the COB EST today - as I'll either be unemployed or finished.  If I finish, I'll surely post my solution.

Expert help is always appreciated!
0
Comment
Question by:sjd01032
  • 3
  • 3
  • 2
8 Comments
 
LVL 15

Accepted Solution

by:
mohan_sekar earned 500 total points
ID: 24314929
this will do it
VB.net
--------
Dim eArgs As New EventArgs
listView_SelectedIndexChanged(listView, eArgs)
0
 
LVL 6

Expert Comment

by:MrJesse34
ID: 24315254
Set the control to AutoPostBack = true?
0
 

Author Comment

by:sjd01032
ID: 24315699
So far mohan_sekar's solutions is working (in my prototype)!  I was headed down this path but wasn't sure if the ListView would suffice as the Sender object (but we're not using it - so it doesn't matter!).

Thank you and if it works in the real databound listview I'll post this as your solution!
0
 

Author Comment

by:sjd01032
ID: 24316152
No, no dice.  It's the same problem I had before:

The first time thru, the SelectedData, DataItems, etc. are all good.  But once I click that radio button and have it postback they are null.

I'm doing the databind in OnInit if NOT postback - which seems okay and renders okay - but something tells me I need to rebind??
protected void listViewSort_SelectedIndexChanged(Object sender, EventArgs e)

{

    Int32? selectedUid = ((Int32?)listViewSort.SelectedDataKey.Values[0]) ?? null;

    lblTest.Text = String.Format("ID: {0}", selectedUid);

}

Open in new window

0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 6

Expert Comment

by:MrJesse34
ID: 24316163
Is it a custom control of any type?  It might be losing the state in viewstate.
0
 
LVL 15

Expert Comment

by:mohan_sekar
ID: 24316233
when you say "they are null", do you mean the selectedItem is null?
Just to make sure I understand your question - you've a listview. The 1st column in your list view if a radio button. On click on radio button, you want to do something on the server side. Is that right? Or, there is more to it?
0
 
LVL 6

Expert Comment

by:MrJesse34
ID: 24316249
Yeah, if I had to do this I would just set the AutoPostBack = true property on the list view
0
 

Author Comment

by:sjd01032
ID: 24317038
There is no AutoPostBack property for a ListView.

I do have the RadioButton's AutoPostBack property set though.

When I click another control after selecting the radiobutton on the listview, the listview's SelectedDataKey is null.  I just put the value into viewstate and pull it where I need it.

Thanks again mohan_sekar!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
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: …

743 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

11 Experts available now in Live!

Get 1:1 Help Now