9 Answers, 1 is accepted
0
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
answered on 12 Dec 2009, 08:53 PM
What about if you handle the DataBound event of the control
http://www.telerik.com/help/aspnet-ajax/listview-selecting-items.html
Steve
if (radListView1.Items.Count > 0) |
radListView1.Items[0].Selected = true; |
http://www.telerik.com/help/aspnet-ajax/listview-selecting-items.html
Steve
0
Rod
Top achievements
Rank 1
answered on 13 Dec 2009, 12:53 AM
I tried using the following:
...along with...
And it threw the page into an endless loop (although it did correctly select the first item in my RadListView each time!).
Any ideas? Does the "fireCommand("Select", itemIndex)" method have to force a reload of the listview, or can I prevent that?
Thanks,
Rod
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server"> |
<script type="text/javascript"> |
var listView = null; |
function optionSelect() { |
var listview = $find("<%= lvOptions.ClientID %>"); |
listview.fireCommand("Select", 0); |
} |
</script> |
</telerik:RadCodeBlock> |
...along with...
<telerik:RadListView ID="lvOptions" runat="server" |
ItemPlaceholderID="pnlOptionsPlaceholder" DataKeyNames="OptionID" |
DataSourceID="dsOptions"> |
<ClientSettings> |
<ClientEvents OnListViewCreated="optionSelect" /> |
</ClientSettings> |
... |
And it threw the page into an endless loop (although it did correctly select the first item in my RadListView each time!).
Any ideas? Does the "fireCommand("Select", itemIndex)" method have to force a reload of the listview, or can I prevent that?
Thanks,
Rod
0
Rod
Top achievements
Rank 1
answered on 13 Dec 2009, 12:57 AM
Steve -
Tried that; no joy. Have you been able to make it work?
Rod
Tried that; no joy. Have you been able to make it work?
Rod
0
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
answered on 13 Dec 2009, 01:33 AM
Unless I'm misreading the docs that should be working, but no I havent been able to get it to work. It appears that the client-side select causes a postback so setting selecting it on a clientside pageload event will cause it to postback everytime :o
0
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
answered on 13 Dec 2009, 02:02 AM
* Deleted
0
Accepted
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
answered on 13 Dec 2009, 02:25 AM
Ok, this works
Must be becasue of some funky lifecycle deal
protected void listView_ItemDataBound(object sender, RadListViewItemEventArgs e) { |
RadListViewDataItem item = e.Item as RadListViewDataItem; |
if(item.DisplayIndex == 0) |
item.Selected = true; |
} |
protected void listView_PreRender(object sender, EventArgs e) { |
listView.Rebind(); |
} |
Must be becasue of some funky lifecycle deal
0
Rod
Top achievements
Rank 1
answered on 13 Dec 2009, 06:02 AM
Steve -
Funky is the word...but it works. I had to wrap both in "Not IsPostBack" qualifiers to prevent them from firing each time I clicked a new selection:
I wouldn't have thought of that - thanks for your help.
Rod
Funky is the word...but it works. I had to wrap both in "Not IsPostBack" qualifiers to prevent them from firing each time I clicked a new selection:
Protected Sub lvOptions_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadListViewItemEventArgs) Handles lvOptions.ItemDataBound |
If Not IsPostBack Then |
Dim itmRow As RadListViewDataItem = e.Item |
If itmRow.DisplayIndex = 0 Then |
itmRow.Selected = True |
End If |
End If |
End Sub |
Protected Sub lvOptions_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles lvOptions.PreRender |
If Not IsPostBack Then |
lvOptions.Rebind() |
End If |
End Sub |
I wouldn't have thought of that - thanks for your help.
Rod
0
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
answered on 15 Dec 2009, 04:13 AM
No problem, would you mind clicking Mark as Answer? :)
0
hart
Top achievements
Rank 1
Veteran
answered on 31 Dec 2016, 11:31 PM
7 years later and this answer still works!!
Happy New Year!