开发者

How can I set a ListView's selected item based on it's ID in a query string on page load?

Question basically crams it all in... I'm load开发者_如何学Pythoning a page with a querystring (ID), and I need to use that ID to set the selected item of a ListView when the page loads. The ID is a DataKey on the ListView. Please help!

I have no code of value to post--none of my attempts at this work.


My first answer was not so clever, mixed up listbox and listview, so i'll try again:

ListView1.DataSource = New String() {"i1", "i2", "i3", "i4", "i5"}
ListView1.SelectedIndex = 3
ListView1.DataBind()

if i put the second line last it does not work, Databind has to be called after setting the selectedindex, but you can also call Databind a second time, after setting the SelectedIndex


Something like this untested from memory

sId = Request.QueryString("id")
if NOT( string.NotisnullorEmpty(sId)) then
  Listbox.SelectedValue = sId
end if
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜