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

P

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.
 
G

George Durzi

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());
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top