Display Image on GridView Select

  • Thread starter Richard T. Henry
  • Start date
R

Richard T. Henry

I have a GridView that I would like to have an image display in a column
on the gridview when that row is selected. This would help the user know
which row has been selected. Any suggestions?
 
S

Stan

I have a GridView that I would like to have an image display in a column
on the gridview when that row is selected.  This would help the user know
which row has been selected.  Any suggestions?  

First, convert the column that you require to contain the image to a
Template column (use the design wizard if preferred).
Second, go into edit tempates and select the "SelectedItemTemplate"
for same column.
Third insert your image into that template.

At each stage you may need to add a label or some other display
control and bind it to the relevent database column in order to
display the column value.

One other thing (this may not be pertinent) you can if you wish bind
the image control's url to an expression involving a column value
(using Eval() function) if you want to vary the actual image according
to the selected row.

HTH
 
R

Richard T. Henry

First, convert the column that you require to contain the image to a
Template column (use the design wizard if preferred). Second, go into
edit tempates and select the "SelectedItemTemplate" for same column.
Third insert your image into that template.

At each stage you may need to add a label or some other display control
and bind it to the relevent database column in order to display the
column value.

One other thing (this may not be pertinent) you can if you wish bind the
image control's url to an expression involving a column value (using
Eval() function) if you want to vary the actual image according to the
selected row.

HTH


Thanks for the suggestion. However the gridview does not have a selected
item template. DataList does.
 
S

Stan

Thanks for the suggestion.  However the gridview does not have a selected
item template.  DataList does.  

--
Richard T. Henry
Lewisberry, PA- Hide quoted text -

- Show quoted text -

Ah I see. Yes you are right if the GridView had a template option for
the selected row then it would be called "SelectedRowTemplate" rather
than "SelectedItemTemplate" ("item" is DataList terminology). DataList
is of course template only.

The alternative is to add a template column to the GridView and put
the the image control in there (or alternatively add an image to an
existing templated column if preferred). Set the visible property of
the image to false in the designer.

Then write some code for both the SelectedIndexChanging event and the
SelectedIndexChanged event.

In the SelectedIndexChanging event handler check for a non-negative
value of SelectedIndex and if so set the image visible property to
false in the SelectedRow (use the FindControl() method of the
SelectedRow object to retrieve it). This will hide the image for the
previously selected row if it existed.

In the SelectedIndexChanged event handler set the visible property of
the image in the SelectedRow to true. This will show the image for the
newly selected row.

HTH

(BTW I know the above works because I tried it).
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top