473,394 Members | 1,965 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Image with link in a gridview?

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
5 2091
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Wlad | last post by:
Hi, Does anybody knows how to make the browser lauch an external image editor (i.e. Photoshop) when the user clicks on a link like this : <a href=...
2
by: Madame Blablavatsky | last post by:
hello, i have an image that is also a link: <a href="javascript:opmaak('bold','')"><img src='bold_uit.gif name='uit'></a> when the image/link is clicked it triggers a javascript that...
1
by: Tan | last post by:
Hi I am desperate for any help with display image in Gridview I have a gridview contain surname , forename ..... and image. I could not display image as my database store the column image as...
5
by: Mel | last post by:
i like to place an image link on my page that stays up for 2 seconds and user can interact with. if no interaction in 2 seconds the image and the link should disapear please help
2
by: manmit.walia | last post by:
Hello Fellow Developers, I have a small problem that you might be able to help me with. The method that I am trying to create is the ability to export a GridView and a image to word or excel. I...
1
by: staeri | last post by:
I want to display a background image in the header of my GridView but when I do that by setting HeaderImageUrl="..." the HeaderText isn't visible. It seems to me that either I can show the...
6
by: fredo | last post by:
A few days ago, Jim answered (THANK YOU, Jim) my question about how to make an image pop up when an image link is hovered. That discussion is here: ...
1
by: imranabdulaziz | last post by:
Dear All, I am using asp.net2.0, sql 2005 I am storing Image url in database. through that url i would like to show images in gridview I want to know is it possible to show images in gridview. ...
3
by: zion | last post by:
Hello, How can I return image link with webservice that I could see it in web page? The image is on my hard disk and <img src="c:\pictures\test.jpg" /does not work. If I use <img src=http://My...
3
by: mcfly1204 | last post by:
I have an image link, an image within an anchor tag, that I would like to remove the styling of. When I say styling, I mean the default blue box around the image. I have tried: text-decoration:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.