468,549 Members | 2,145 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,549 developers. It's quick & easy.

Set DataList SelectedIndex - 2nd Post

This is the second post for this question....please help!!

This is a fairly simple request....I am looking for some help....

I want to set the SelectedIndex of a DataList control to equal a specific
record in the database. What is the easiest way to accomplish this??
Thanks,
David D. McCrory
Nov 18 '05 #1
2 2901
David D. McCrory wrote:
This is the second post for this question....please help!!

This is a fairly simple request....I am looking for some help....

I want to set the SelectedIndex of a DataList control to equal a specific
record in the database. What is the easiest way to accomplish this??
Thanks,
David D. McCrory


I would add a handler for the ItemDataBound event of the DataList and
then the event args give you access to the current item and its data.

e.Item.DataItem gives the current item in the datasource; use this to
check for a certain value
e.Item.ItemIndex gives the current item's index

I believe you can set the selectedindex in this event; if not, set a
local/member var to the value and then after the DataBind, set it.

The other solution is to loop the items after the DataBind instead of
using the event, but doing the first way does one less loop.

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Nov 18 '05 #2
Thanks Craig...I will give it a try......

"Craig Deelsnyder" <cdeelsny@NO_SPAM_4_MEyahoo.com> wrote in message
news:OO**************@tk2msftngp13.phx.gbl...
David D. McCrory wrote:
This is the second post for this question....please help!!

This is a fairly simple request....I am looking for some help....

I want to set the SelectedIndex of a DataList control to equal a specific record in the database. What is the easiest way to accomplish this??
Thanks,
David D. McCrory


I would add a handler for the ItemDataBound event of the DataList and
then the event args give you access to the current item and its data.

e.Item.DataItem gives the current item in the datasource; use this to
check for a certain value
e.Item.ItemIndex gives the current item's index

I believe you can set the selectedindex in this event; if not, set a
local/member var to the value and then after the DataBind, set it.

The other solution is to loop the items after the DataBind instead of
using the event, but doing the first way does one less loop.

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET

Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by V. Jenks | last post: by
3 posts views Thread by CVerma | last post: by
reply views Thread by rbutch | last post: by
1 post views Thread by Gary Frank | last post: by
4 posts views Thread by Chris Kettenbach | last post: by
1 post views Thread by UniDue | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.