470,855 Members | 1,322 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Selecting item in DataList


asp.net 2.0

My webpage has a DataList containing a TemplateField (ImageButton). When the
ImageButton is clicked it becomes the selected ImageButton. This works okay
as it is. But this isn't an ideal solution, because CommandArgument in this
solution will contain a counter (first element have value 0, then 1 etc).
Instead I think it would be better to have some kind of Id from Car object
stored in the CommandArgument so I easier could access to the id of the
selected object. But then I don't know how to set the SelectedIndex when a
ImageButton is clicked..... below is some of my code...

protected void imgThumbnail_Command(object sender, CommandEventArgs e)
dlThumbnails.SelectedIndex = Convert.ToInt32(e.CommandArgument);

protected void dlThumbnails_ItemDataBound(object sender,
DataListItemEventArgs e)

if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem ||
e.Item.ItemType == ListItemType.SelectedItem )
Car car = (Car)e.Item.DataItem;

ImageButton img =
img.CommandArgument = _count.ToString();
_count++; //_count is a class variable, int
//some more logic here


any suggestions?
Nov 3 '08 #1
0 1023

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Fabiano | last post: by
2 posts views Thread by Mike Kelly | last post: by
16 posts views Thread by Vikas Kumar | last post: by
reply views Thread by Gert | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.