469,613 Members | 1,300 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,613 developers. It's quick & easy.

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 6314
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Jason | last post: by
19 posts views Thread by Joe | last post: by
3 posts views Thread by TPhelps | last post: by
8 posts views Thread by Sohan Kamat | last post: by
3 posts views Thread by shapper | last post: by
4 posts views Thread by =?Utf-8?B?QW1pciBUb2hpZGk=?= | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.