Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Selecting item in DataList

Reply
Thread Tools

Selecting item in DataList

 
 
Jeff
Guest
Posts: n/a
 
      11-03-2008
Hi

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 =
(ImageButton)e.Item.FindControl("imgThumbnail");
img.CommandArgument = _count.ToString();
_count++; //_count is a class variable, int
//some more logic here
}

}

any suggestions?


 
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
Selecting item with radiobutton in datalist Gert ASP .Net 0 08-02-2006 08:09 AM
Setting up a datalist control - Item_DataBound for a datalist in a datalist Nevyn Twyll ASP .Net 8 09-09-2004 10:13 PM
Selecting the first item of a datalist ASP .Net Web Controls 1 11-17-2003 04:42 PM
Datalist/Datagrid question concerning selecting item and bringing it into focus SStory ASP .Net Datagrid Control 1 09-22-2003 04:12 PM
Programmatically Selecting Item in Radio Button List John Criswell ASP .Net 1 07-24-2003 07:07 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