472,353 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

C# Hit hyperlink and send a column value to the code behind.

Pat
All,

What I want to do:
*******************
Click on a hyperlink in the last column in a datagrid, have it grab a
value in the fourth column in the same row and send it to the codehind
into a function that will then put the value into a query and send it
off the database.... and do some stuff with the return.

What I have so far:
********************
I have the first part of the program done, the datagrid is populated
and the last column has the hyperlink.

What code I have:
******************
In the .ASPX
=============
<asp:TemplateColumn>
<ItemTemplate>
<asp:HyperLink id="HyperLink2" Runat="server"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>

In the code behind - In the Page Load
======================================
if(Page.Request["Report"]!=null)
ShowReport();

In the code behind
====================
private void grdReceipts_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if((e.Item.ItemType == ListItemType.Item)|| (e.Item.ItemType ==
ListItemType.AlternatingItem))
{
HyperLink c=(HyperLink)e.Item.FindControl ("HyperLink2");
c.Text="Report" ;
c.NavigateUrl='javascript:document.getElementById( "hidCurrentTab").value
= "Detail"; window.open('ItemAudit.aspx?Report=True', 'Report', '')'
}
}
Any help is appreciated.

Thanks,
Pat G.
Nov 17 '05 #1
1 6426
Pat,
How about using an asp:LinkButton instead of the hyperlink.

You could do something like this:

protected void dgIrResources_OnItemCreated(Object sender,
DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
LinkButton button = (LinkButton ) e.Item.Cells[0].Controls[0];
button.Attributes.Add("onclick",
"return confirm(\"Are you sure you want to delete this document? You
cannot submit an Invoice Request to Accounting without an attached
Reconciliation Document\");");
}
}

What I'm doing is using .Attributes.Add to add a javascript confirm to the
onclick event of the LinkButton.
You could use a stringbuilding to build your javascript

StringBuilder sb = new StringBuilder();

sb.Append ( blah blah);

then do:

button.Attributes.Add("onclick", sb.ToString());
"Pat" <pg******@52monkeys.com> wrote in message
news:1c**************************@posting.google.c om...
All,

What I want to do:
*******************
Click on a hyperlink in the last column in a datagrid, have it grab a
value in the fourth column in the same row and send it to the codehind
into a function that will then put the value into a query and send it
off the database.... and do some stuff with the return.

What I have so far:
********************
I have the first part of the program done, the datagrid is populated
and the last column has the hyperlink.

What code I have:
******************
In the .ASPX
=============
<asp:TemplateColumn>
<ItemTemplate>
<asp:HyperLink id="HyperLink2" Runat="server"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>

In the code behind - In the Page Load
======================================
if(Page.Request["Report"]!=null)
ShowReport();

In the code behind
====================
private void grdReceipts_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if((e.Item.ItemType == ListItemType.Item)|| (e.Item.ItemType ==
ListItemType.AlternatingItem))
{
HyperLink c=(HyperLink)e.Item.FindControl ("HyperLink2");
c.Text="Report" ;
c.NavigateUrl='javascript:document.getElementById( "hidCurrentTab").value
= "Detail"; window.open('ItemAudit.aspx?Report=True', 'Report', '')'
}
}
Any help is appreciated.

Thanks,
Pat G.

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Paul | last post by:
Hi I have a data grid with a hyperlink column. the colum has numbers like 00001,000002, ect. Just wondering how to get the text value of the cell...
4
by: Tomek R. | last post by:
Hello ! This post does'nt regard column hyperlink. I just have single hyperlink and want to create it's NavigateUrl dynamically. This is my...
2
by: Jason | last post by:
I have a data grid with a hyperlink column. The hyperlink is created by a class that extracts the link from an XML Document. How can I populate...
19
by: Joe | last post by:
I have an aspx page (referred to here as page_1) with a datagrid whose first column contains hyperlinks. When a user clicks one of these...
3
by: TPhelps | last post by:
I have a sample of an unbound (autogeneratecolumns is true) sortable/pagable datagrid that works. I want to change one of the columns to a...
8
by: Sohan Kamat | last post by:
Hi, I have a webform and I want to create a hyperlink to a text file, so that it opens on internet explorer in a new window. I have added the...
3
by: shapper | last post by:
Hello, In my GridView I have a HyperLink Field where I set the DataNavigateUrlFormaString MyHyperLinkField.DataNavigateUrlFormatString =...
8
by: johnlim20088 | last post by:
Hi, Hi currently i have a datagrid it have 3 column the 1st column I using databind. however, for column 2 and 3, i never using databind,...
4
by: =?Utf-8?B?QW1pciBUb2hpZGk=?= | last post by:
Hi I have a GridView that is displaying master records. Some of these records have child records. I would like to a column to my master...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...

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.