By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,022 Members | 1,379 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,022 IT Pros & Developers. It's quick & easy.

Image with link in a gridview?

P: n/a
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!
Dec 7 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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

Dec 7 '05 #2

P: n/a
This worked great. In fact, I think I'm gonna use them both.

Tnx!

"Remy" <rb********@hotmail.com> escribió en el mensaje
news:11*********************@g43g2000cwa.googlegro ups.com...
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

Dec 7 '05 #3

P: n/a
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" <rb********@hotmail.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
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

Dec 7 '05 #4

P: n/a
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

Dec 8 '05 #5

P: n/a
Tnx
"Remy" <rb********@hotmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
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

Dec 9 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.