Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need datagrid hyperlink to call subroutine when clicked 1

Status
Not open for further replies.

lanm

Programmer
Jul 7, 2005
244
US
I've got a hyperlink in a datagrid:
<asp:hyperlink id=button1

What I need to do is have this hyperlink, once clicked, to call a routine.

How can I do this?

Thanks!
 
I don't think there is a way to do that, you can use a button instead.
 
Use a linkbutton, users wont know the difference

There is no click event for an asp:hyperlink
 
On the dataGrid rightcick Property Builder->Columns and add hyperlink column
Then use the event ItemCommand to call you routine
Here is an example:

Code:
private void DataGrid1_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			if( e.CommandName == "Select")
			{
			     // call the routine here
                        }
	        }

If you want to get which row is clicked use something like this:
Code:
.....
if( e.CommandName == "Select")
			{
			     // call the routine here
                            	string userName =((Label)e.Item.FindControl("idUser")).Text;
                             // some calculations with userName
                        }

Before that in the xml code I added the id value
<asp:Label id="idBranch" runat="server" ....


I am using Label u can do the same with hyperlink or label

Good Luck,
Spent
 
Spent,

Your route was the one I was trying Friday, but I can't get it to work.

****************************
Here's the HTML:
<asp:TemplateColumn>
<HeaderStyle Width="100px"></HeaderStyle>
<ItemStyle Font-Size="7pt" HorizontalAlign="Center" Width="100px"></ItemStyle>
<ItemTemplate>
<asp:hyperlink id=Button1 runat="server" Height="18px" Width="95px" Font-Size="7pt" Text="Milestone Dictionary" NavigateUrl='<%# "MilestoneDescription.aspx?MilestoneNumber=" &amp; DataBinder.Eval(Container, "DataItem.Milestone Number") &amp;"*?WPPID=@" &amp; Request.QueryString("WPPID") %>' Target="_parent">Milestone Dictionary</asp:hyperlink>
</ItemTemplate>
</asp:TemplateColumn>

*****************************
In the code-behind, I've got:
Private Sub DGMilestones_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DGMilestones.ItemCommand
If e.CommandName = "button1" Then
Call WPSaveInfo()
End If
End Sub
 
It won't work. Do as stsuing suggested. Use a link button in a template column.
 
What about the whole Navigate URL with the hyperlink?

NavigateUrl='<%# "MilestoneDescription.aspx?MilestoneNumber=" &amp; DataBinder.Eval(Container, "DataItem.Milestone Number") &amp;"*?WPPID=@" &amp; Request.QueryString("WPPID") %>'

Thanks!
 
What about if I call the routine, WPSaveInfo(), before the user goes to the next page via the hyperlink. WPSaveInfo() saves the data the user entered on the page, just in case they didn't click the SAVE button.

I know the script is something like the following, but I don't have it correct:

Dim strScript As String
strScript =
"<script language="JavaScript">
window.onbeforeunload = confirmExit;
function confirmExit()
{
Call WPSaveInfo()
}
<" & Chr(47) & "script> "


Where do I put this javascript? In Page_Unload?
How do I call this WPSaveInfo() routine? I know it's not Javascript.
 
Issue resolved.

1. Changed the hyperlink to a linkbutton.
2. In Datagrid.ItemCommand, looked for the command name of the linkbutton
3. Called the routine needed in this Datagrid handler

Thanks for the help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top