Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Image with link in a gridview?

9 views
Skip to first unread message

Carlos Albert

unread,
Dec 7, 2005, 8:49:38 AM12/7/05
to
Hi everyone,

Is there a way to make a column that has an image with a hyperlink on it?
Cause I know how to make a hyperlink column, and a image column, but not how
to mix it both...

Tnx!


Remy

unread,
Dec 7, 2005, 9:41:09 AM12/7/05
to
There are actually a bunch of different ways you can do that.
Do you want this to be a link that leads to another page, or more
something like a button that causes a callback?

For a callback I use a ButtonColumn, set following things:
Text:
<img src="Resources/images/Delete.gif?" width="18" height="18"
border="0" Alt="Delete this Trade">
Command:
cmdDelete
Button Type:
Link Button

For a link (it's actually with javascript, but you get the idea) I use
a plain BoundColumn:

Data formating expression:
<A HREF=javascript:onClick=OpenNTMWindow({0});><img
src="Resources/images/XmlSign.gif?" width="18" height="18" border="0"
Alt="Show NTM Message"></a>
Data Field:
Whatever column from the db you wanna have in the {0} placeholder
above.

Hope that helps. You can build some pretty powerfull stuff this way.

Cheers

Remy Blaettler
www.collaboral.com

Carlos Albert

unread,
Dec 7, 2005, 9:56:32 AM12/7/05
to
This worked great. In fact, I think I'm gonna use them both.

Tnx!

"Remy" <rblae...@hotmail.com> escribió en el mensaje
news:1133966469....@g43g2000cwa.googlegroups.com...

Carlos Albert

unread,
Dec 7, 2005, 11:55:56 AM12/7/05
to
Hello again Remy,

I used the javascript just fine. Now I was trying to use the "real" button,
but I came across a problem. The button is in a gridview inside another
gridview. How can I now wich record the user "selected" pressing the button?

"Remy" <rblae...@hotmail.com> wrote in message
news:1133966469....@g43g2000cwa.googlegroups.com...

Remy

unread,
Dec 8, 2005, 9:59:44 AM12/8/05
to
Yeah, that is a bit tricky I think, but below is a way to do it. (I'm
sure there are better ways):

private void dgErrorMessages_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
OdbcConnection execConn = null;
int rowID;

if (e.CommandName == "cmdResend")
{
//ItemIndex is only available if it is a command from a
row, but we also get the Page
//command in here
rowID = Convert.ToInt32(e.Item.Cells[3].Text);
log.Info("cmdResend - RowID = " + rowID);

try
{
execConn =
DatabaseUtils.OpenDatabaseConnection("Executive");

lbResult.Text = coreLogic.ResendNtmMessage(rowID,
coreLogic.GetStartDate(cldrStart), coreLogic.GetEndDate(cldrEnd),
execConn);
FillAndBindGrid(execConn);
}
finally
{
if(execConn != null) execConn.Close();
}
}
else if (e.CommandName == "cmdDelete")
{
//ItemIndex is only available if it is a command from a
row, but we also get the Page
//command in here
rowID = Convert.ToInt32(e.Item.Cells[3].Text);
log.Info("cmdDelete - RowID = " + rowID);

try
{
execConn =
DatabaseUtils.OpenDatabaseConnection("Executive");

lbResult.Text = coreLogic.DeleteNtmMessage(rowID,
execConn);
FillAndBindGrid(execConn);
}
finally
{
if(execConn != null) execConn.Close();
}
}
}

dgErrorMessages is the name of the grid. ItemCommand is the event
handler for all the commands that are sent via the columns. The command
name is put into the CommandName field in the ButtonColumn
configuration.
But the core is
e.Item.Cells[3]
which is how I get the ID for this column. The ID is in my 3rd column
(or in the 4th, not sure if it zero based anymore).
It's not very nice to hardcode the 3 into the code, but...

Hope that gives you a hint

Cheers

Remy Blaettler
www.collaboral.com

Carlos Albert

unread,
Dec 9, 2005, 9:30:07 AM12/9/05
to
Tnx

"Remy" <rblae...@hotmail.com> wrote in message
news:1134053984.8...@g43g2000cwa.googlegroups.com...
0 new messages