Ask a Question related to ASP.NET Data Grid Control, Design and Development.
-
MW #1
Changing an image in a datagrid column in the ItemDataBound event
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
MW Guest
-
ItemDataBound Event - How to access the previous record when this event is raised in DataGrid?
ItemDataBound Event - How to access the previous record when this event is raised in DataGrid? During "ItemDataBound Event", I would like... -
how do i access a dropdownlists selected value in a datagrid edititemtemplate column from the selectedindexchanged event of another dropdownlist in a datagrid edititemtemplate column
i am trying to trap the value of one dropdownlist (in a datagrid edititemtemplate column) at the time its selectedindexchanged event fires and use... -
formating column in the ItemDataBound event
Ken wrote: Ken, check out this example: http://tinyurl.com/4dubw -- Scott Mitchell mitchell@4guysfromrolla.com... -
Changing ImageURL of Image Button which is added in template column of datagrid
hello, I have a template column in my datagrid. To the header of template colum, i have added imagebutton. On click of the imagebutton , i... -
getting column value in ItemCreated datagrid event
got it. use DataItem("columnname"( "Learning SQL Server" <no.mail.com> wrote in message news:ulsj5VNYDHA.4040@tk2msftngp13.phx.gbl...... -
Eliyahu Goldin #2
Re: Changing an image in a datagrid column in the ItemDataBound event
Does the code set bolClosed correctly to true/false depending on the
"Closed" field content?
BTW, why are you using myDataTable.Rows (e.Item.ItemIndex).Item("Closed")
instead of simple e.Item("Closed")?
Eliyahu
"MW" <anonymous@discussions.microsoft.com> wrote in message
news:791d01c49511$e11e79b0$a501280a@phx.gbl...> 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
Eliyahu Goldin Guest
-
MW #3
Re: Changing an image in a datagrid column in the ItemDataBound event
Hi Eliyau,
thanks for the response. I was able to solve my problem
based on what you told me. I couldn't use e.Item
("Closed"), but e.Item.DataItem("Closed") gave me the
proper value.
There is a difference between what myDataTable.Rows
(e.Item.ItemIndex).Item("Closed") returns as a value and
what e.Item.DataItem("Closed") returns.
So, the difference must be because the View of the
datatable is sorted, not the datatable?
Thanks,
depending on the>-----Original Message-----
>Does the code set bolClosed correctly to true/false(e.Item.ItemIndex).Item("Closed")>"Closed" field content?
>
>BTW, why are you using myDataTable.Rowsmessage>instead of simple e.Item("Closed")?
>
>Eliyahu
>
>"MW" <anonymous@discussions.microsoft.com> wrote inusing>news:791d01c49511$e11e79b0$a501280a@phx.gbl...>> Hi,
>>
>> I have a datagrid that is bound to a datatable, I'mthe>> 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 onthe>> column value (which I know is sorting properly), butwhy.>> images aren't changing. I can't seem to figure oute.Item.ItemType>>
>> 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(1).Controls>> = 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), WebControls.Image)
>> imgStatus.ImageUrl =
>> Request.ApplicationPath & "/Images/open.gif"
>> End If
>> End If
>
>.
>MW Guest



Reply With Quote

