Set DataList SelectedIndex - 2nd Post

D

David D. McCrory

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
 
C

Craig Deelsnyder

David said:
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.
 
D

David D. McCrory

Thanks Craig...I will give it a try......

Craig Deelsnyder said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top