Solved

Need ASP.NET ListView to fire SelectedIndex events

Posted on 2009-05-06
8
1,706 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 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
Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

 

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

Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

Question has a verified solution.

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

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 …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

691 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