Solved

Need ASP.NET ListView to fire SelectedIndex events

Posted on 2009-05-06
8
1,704 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

756 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