?
Solved

Need ASP.NET ListView to fire SelectedIndex events

Posted on 2009-05-06
8
Medium Priority
?
1,711 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
[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
  • 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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

650 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