Datagrid query

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)
 
J

Jon Sequeira

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
 
J

John G

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top