Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Set DataList SelectedIndex - 2nd Post

Reply
Thread Tools

Set DataList SelectedIndex - 2nd Post

 
 
David D. McCrory
Guest
Posts: n/a
 
      01-20-2004
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


 
Reply With Quote
 
 
 
 
Craig Deelsnyder
Guest
Posts: n/a
 
      01-20-2004
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
 
Reply With Quote
 
 
 
 
David D. McCrory
Guest
Posts: n/a
 
      01-20-2004
Thanks Craig...I will give it a try......

"Craig Deelsnyder" <cdeelsny@NO_SPAM_4_MEyahoo.com> wrote in message
news:...
> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataList (ASP.NET 2.0) set/reset SelectedIndex to -1 Jules ASP .Net 1 07-12-2006 12:53 PM
setting SelectedIndex of DataList nested inside of DataList? Les Caudle ASP .Net 0 05-02-2006 10:44 PM
Setting up a datalist control - Item_DataBound for a datalist in a datalist Nevyn Twyll ASP .Net 8 09-09-2004 10:13 PM
datalist and selectedindex please helpppppppppppppppppppp =?Utf-8?B?bWFoc2E=?= ASP .Net 1 04-30-2004 10:15 AM
Set DataList SelectedIndex to data record David D. McCrory ASP .Net 2 01-24-2004 10:17 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57