Datagrid query

  • Thread starter Thread starter Carl Howarth
  • Start date Start date
C

Carl Howarth

Hi,

I have a datagrid being populated using an sqldatareader. One of the
columns returns a bit value which currently gets displayed as 'True' or
'False'.

I would like to be able to display an image of a tick when this value is
true, and have placed an asp.net image control within the relevant template
column. I presume I can achieve this within the databinding event of the
grid, but am unsure as to quite how!

I would be grateful if anyone could shed some light on this!

Many thanks, Carl
(e-mail address removed)
 
In the .aspx file you could set the Image's Visible property to the
databound value, something like this:

<asp:Image Visible="<%# CBool(DataBinder.Eval(Container,
"DataItem.showTickGraphic") %>"> </asp:Image>

If this will acheive what you're looking for, it's a little less complex
than diving into the databinding events.

Hope that's useful,

--Jon
 
Hi Carl,

From what I can see you are in the right direction but you cannot use
the FindControl method of the DataGrid itself to find a control in a
templatecolumn... there would be one control with that ID for each row
in the grid.

So... instead of

dgExistingFiles.Controls("imTick").Visible = True

you need to use the DataGridItemEventArgs e param that is passed in to
get
a reference to the control. For ex: if your image is the only control
in the first column of the datagrid:

e.Item.Cells[0].Controls[1].Visible = false

would do the trick (Controls[1] because the system always adds a
literal control before your server control, at least this is what I
have found)

If its in the second column use Cells[1] instead, etc... If there are
other controls in the column you will have to play around with the
Controls[] index to find the right one.

John
 
Back
Top