I have a databound ListView in asp.Net. I have both ItemTemplate and SelectedItemTemplate used in the aspx page.
In the .cs page I have this. I have verified by stepping through the code that the if statement evaluates to true only when it is supposed to, and that the selected index is set. However the HTML output is as if all items use the ItemTemplate.
int indexCounter = 0;
protected void lvProducts_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
if (((DataRowView)e.Item.DataItem)["ID"].ToString() == Request.QueryString["id"])
{
lvProducts.SelectedIndex = indexCounter;
}
indexCounter++;
}
}
Is there a better way to do this?