M
MW
Hi,
I have a datagrid that is bound to a datatable, I'm using
TemplateColumns.
The heading of two columns of the datagrid fire the
ItemCommand event in which I sort the datatable then
rebind to the datagrid. One column is an image (which
the imageurl is set in the first binding of the grid).
On the ItemDataBound event after the sort when the
datatable is re-binded to the grid, I go through the
datatable because I want to change the image based on the
column value (which I know is sorting properly), but the
images aren't changing. I can't seem to figure out why.
on the aspx page:
<asp:TemplateColumn>
<ItemTemplate>
<asp:Image Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
in the code behind (ItemDataBound event):
Dim bolClosed as Boolean
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType
= ListItemType.AlternatingItem Then
bolClosed = CType(myDataTable.Rows
(e.Item.ItemIndex).Item("Closed"), Boolean)
If bolClosed Then
imgStatus = CType(e.Item.Cells(1).Controls
(1), WebControls.Image)
imgStatus.ImageUrl =
Request.ApplicationPath & "/Images/closed.gif"
Else
imgStatus = CType(e.Item.Cells(1).Controls
(1), WebControls.Image)
imgStatus.ImageUrl =
Request.ApplicationPath & "/Images/open.gif"
End If
End If
I have a datagrid that is bound to a datatable, I'm using
TemplateColumns.
The heading of two columns of the datagrid fire the
ItemCommand event in which I sort the datatable then
rebind to the datagrid. One column is an image (which
the imageurl is set in the first binding of the grid).
On the ItemDataBound event after the sort when the
datatable is re-binded to the grid, I go through the
datatable because I want to change the image based on the
column value (which I know is sorting properly), but the
images aren't changing. I can't seem to figure out why.
on the aspx page:
<asp:TemplateColumn>
<ItemTemplate>
<asp:Image Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
in the code behind (ItemDataBound event):
Dim bolClosed as Boolean
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType
= ListItemType.AlternatingItem Then
bolClosed = CType(myDataTable.Rows
(e.Item.ItemIndex).Item("Closed"), Boolean)
If bolClosed Then
imgStatus = CType(e.Item.Cells(1).Controls
(1), WebControls.Image)
imgStatus.ImageUrl =
Request.ApplicationPath & "/Images/closed.gif"
Else
imgStatus = CType(e.Item.Cells(1).Controls
(1), WebControls.Image)
imgStatus.ImageUrl =
Request.ApplicationPath & "/Images/open.gif"
End If
End If