[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 458
  • Last Modified:

HyperLink Format.

I need to change the HyperLink control and all it's associated properties into a LinkButton. Is this possible?

HyperLink:
<asp:HyperLink ID="HyperLink1" NavigateUrl='<%# "Schedule.aspx?ghaoc_id=" + Eval("ghaoc_id") + "&ghaocp_id=" + Eval("ghaocp_id") %>' runat="server" Text="Schedule" />

Needs changed to LinkButton using same NaviageURL info.
0
asp_net2
Asked:
asp_net2
  • 3
  • 2
1 Solution
 
quizwedgeCommented:
Change it to <asp:LinkButton ID="HyperLink1" CommandName="HyperLink" CommandArgument='<%# "Schedule.aspx?ghaoc_id=" + Eval("ghaoc_id") + "&ghaocp_id=" + Eval("ghaocp_id") %>' runat="server" Text="Schedule" />

The CommandName can be whatever. Then, in the ItemCommand function for the repeater / datagrid / whatever you have this hyperlink in you'll need to check for the command name "HyperLink"

If e.CommandName = "HyperLink" Then
     Response.Redirect(e.CommandArgument)
End If
0
 
asp_net2Author Commented:
Below is my current Repeater that has the HyperLink Control.


<asp:Repeater runat="server" ID="myRepeater">
            <ItemTemplate>
                <asp:PlaceHolder ID="PlaceHolder1" runat="server" Visible='<%# lastCourseName != Eval("ghaocp_name").ToString() %>'>
                    <asp:PlaceHolder ID="PlaceHolder2" runat="server" Visible='<%# lastCourseName != null %>'>
                        <tr>
                            <td colspan="4">
                                <hr />
                            </td>
                        </tr>
                    </asp:PlaceHolder>
                    <tr>
                        <td colspan="2" class="CourseDescTitle">
                            <%# lastCourseName = Eval("ghaocp_name").ToString()%>
                        </td>
                        <td colspan="2" style="text-align: center;">
                            <asp:HyperLink ID="HyperLink1" NavigateUrl='<%# "Schedule.aspx?ghaoc_id=" + Eval("ghaoc_id") + "&ghaocp_id=" + Eval("ghaocp_id") %>' runat="server" Text="Schedule" />
                        </td>
                    </tr>
                </asp:PlaceHolder>
                <tr>
                    <td class="CourseUpdateInfo">
                        <%# Convert.ToDateTime(Eval("csch_startdate")).ToLongDateString()%>
                    </td>
                    <td class="CourseUpdateInfo">
                        <%# Eval("hmi_name").ToString()%>
                    </td>
                    <td class="CourseUpdateInfo">
                        <%# Eval("csch_starttime").ToString()%>
                    </td>
                    <td class="CourseUpdateInfo">
                        <%# Eval("csch_endtime").ToString()%>
                    </td>
                </tr>
            </ItemTemplate>
        </asp:Repeater>

Open in new window

0
 
quizwedgeCommented:
You'll change line 16 to what I wrote above. The second part goes in your codebheind. Are you using VB or C#?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
asp_net2Author Commented:
using C#
0
 
Carlos VillegasFull Stack .NET DeveloperCommented:
Hello @asp_net2, I did the changes to your code:

Code behind:
protected void myRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
{
    if (e.CommandName == "Schedule")
    {
        string yourNavigateUrl = e.CommandArgument.ToString();
    }
}

Open in new window


html:
<asp:Repeater runat="server" ID="myRepeater" OnItemCommand="myRepeater_ItemCommand">
    <ItemTemplate>
	<asp:PlaceHolder ID="PlaceHolder1" runat="server" Visible='<%# lastCourseName != Eval("ghaocp_name").ToString() %>'>
	    <asp:PlaceHolder ID="PlaceHolder2" runat="server" Visible='<%# lastCourseName != null %>'>
		<tr>
		    <td colspan="4">
			<hr />
		    </td>
		</tr>
	    </asp:PlaceHolder>
	    <tr>
		<td colspan="2" class="CourseDescTitle">
		    <%# lastCourseName = Eval("ghaocp_name").ToString()%>
		</td>
		<td colspan="2" style="text-align: center;">
			<asp:LinkButton Text="Schedule" runat="server" CommandName="Schedule" CommandArgument='<%# "Schedule.aspx?ghaoc_id=" + Eval("ghaoc_id") + "&ghaocp_id=" + Eval("ghaocp_id") %>' />
		</td>
	    </tr>
	</asp:PlaceHolder>
	<tr>
	    <td class="CourseUpdateInfo">
		<%# Convert.ToDateTime(Eval("csch_startdate")).ToLongDateString()%>
	    </td>
	    <td class="CourseUpdateInfo">
		<%# Eval("hmi_name").ToString()%>
	    </td>
	    <td class="CourseUpdateInfo">
		<%# Eval("csch_starttime").ToString()%>
	    </td>
	    <td class="CourseUpdateInfo">
		<%# Eval("csch_endtime").ToString()%>
	    </td>
	</tr>
    </ItemTemplate>
</asp:Repeater>

Open in new window

0
 
asp_net2Author Commented:
Thank you very much for helping with this post!!!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now