J
Jeff
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?
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?