CodeCharge Studio All ASP PHP Perl ColdFusion Java C#.NET VB.NET

Dynamically Modify a Hyperlink

Description

This example shows how to dynamically modify a hyperlink for the Link and Image Link controls.

Method 1

Use this method if you have all required data in database fields and want to lay-out controls in HTML.

  1. Use the Toolbox to create one or more Label controls
  2. In the Control Source property set up the database field that will be used as the link name
  3. Modify the HTML for the link as shown below:
 <a href="{label1}?parameter={label2}">{label3}</a>

Method 2

Use this method if you have all required data in database fields and want to modify hyperlink parameters only.

  1. Use the Toolbox to add a Link or Image Link control to the form
  2. Specify the text to be shown for the link by selecting a database column in Control Source property
  3. Specify the hyperlink by selecting a database column in Href Source property
  4. Click the icon on the right side of the Href Source property in the Properties window
  5. Add the required parameters

Method 3

Use this method if you want to have full control over the hyperlink modification.

  1. Use the Toolbox to add a Link or Image Link control to the form
  2. Add an event that will allow you to modify the control's value:

    Use the Before Show Row event for the Grid or Editable Grid form or

    Use the Before Show event for a control or the Record form.

  3. Inside the event, add the code below:

ASP

Function Users_Link1_BeforeShowRow(Sender)

  Link1.Page = "UserPage.asp"
  Link1.Parameters = CCAddParam(Link1.Parameters, "user_id", "1")
  Link1.Value = Users.First_Name &" "& Users.Last_Name

End Function

PHP

function Users_Link1_BeforeShowRow(& $sender) {
global $Users;

  $Users->Link1->Page = "UserPage.php";
  $Users->Link1->Parameters = CCGetQueryString("QueryString", "");
  $Users->Link1->Parameters = CCAddParam($Users->Link1->Parameters, "user_id", "1");
  $Users->Link1->SetValue($Users->First_Name->GetValue() ." ". $Users->Last_Name->GetValue()) ;

}

Perl

sub Users_Link1_BeforeShowRow() {

 $Users->{Link1}->{Page} = "UserPage.cgi";
 $Users->{Link1}->{Parameters} = CCGetQueryString("QueryString", "");
 $Users->{Link1}->{Parameters} = CCAddParam($Users->{Link1}->{Parameters}, "user_id", "1");
 $Users->{Link1}->SetValue($Users->First_Name->GetValue() ." ". $Users->Last_Name->GetValue()) ;

}

ColdFusion

<!---Users_BeforeShowRow --->

  <CFSET fldLink1 =fldFirst_Name & " " & fldLast_Name>
  <CFMODULE Template="CCGetQueryString.cfm" strCollection="QueryString" arrRemoveParameters="#ListToArray('CFID;CFTOKEN',';')#">
  <CFMODULE Template="CCAddParam.cfm" strQueryString="#CCGetQueryString#" strName="user_id" strValue="#flduser_id#" outputVar="CCGetQueryString">
  <CFSET fldLink1Link="UserPage.cfm" & IIF(CCGetQueryString NEQ "","'?#CCGetQueryString#'","''")>

Java

//Users BeforeShowRow

  Link link1 = e.getGrid().getLink("Link1");
  link1.setHrefSourceValue("UserPage.do");
  link1.setPreserveType(PreserveParameterType.GET);
  link1.clearParameters();
  LinkParameter userId = new LinkParameter("user_id", "", ParameterSource.EXPRESSION);
  userId.setValue("1");
  link1.addParameter(userId);
  link1.setValue(e.getGrid().getControl("First_Name").getValue() + " " + e.getGrid().getControl("Last_Name").getValue() );

For .NET

Use this method if you want to have full control over the hyperlink modification.
  1. Use the Toolbox to add a Link or Image Link control to the form
  2. In the Before Show event of the Link, add the code below

VB.Net

'Tasks_Link1_BeforeShow

  item.Link1HrefParameters.Add("user_id",1)
  Link1.HRef = "UserPage.aspx" & item.Link1HrefParameters.ToString("GET","")
  Link1.InnerText = UsersFirst_Name &" "& UsersLast_Name

C#

//Task_Link1_BeforeShow

  item.Link1HrefParameters.Add("user_id",1);
  Link1.HRef = "UserPage.aspx" + item.Link1HrefParameters.ToString("GET","");
  Link1.InnerText = UsersFirst_Name +" "+ UsersLast_Name;

See Also:

How to create a MailTo hyperlink


On-line, printable versions and updates