?
Solved

Need ASP.NET ListView to fire SelectedIndex events

Posted on 2009-05-06
8
Medium Priority
?
1,713 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 2000 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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
 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

840 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