How to replace a codebehind method with an aspx method using ternary operator
Posted
by
user466663
on Stack Overflow
See other posts from Stack Overflow
or by user466663
Published on 2012-06-17T00:28:55Z
Indexed on
2012/06/17
3:16 UTC
Read the original article
Hit count: 183
ASP.NET
I have an asp:hyperlink control as part of a gridview template. The code in the aspx page is given below:
asp:HyperLink runat="server" ID="lnkEdit" ToolTip="Edit article" NavigateUrl='<%# GetUrl(Eval("ID").ToString(), Eval("CategoryID").ToString()) %>' ImageUrl="~/Images/Edit.gif"
The NavigateUrl value is obtained from the codebehind method GetUrl(string, string). The code works fine and is as follows:
protected string GetUrl(string id, string categoryID) { var CategoryID = string.Empty; if (!String.IsNullOrEmpty(Request.QueryString["CatID"])) { CategoryID = Request.QueryString["CatID"].ToString(); } else if (!String.IsNullOrEmpty(categoryID)) { CategoryID = categoryID; } return "~/TBSArticles/WriteOrEditArticle.aspx?ID=" + id + "&CatID=" + CategoryID; }
I want to replace the code behind method by using a ternary operator within the aspx page. I tried something like below, but didn't work:
asp:HyperLink runat="server" ID="lnkEdit" ToolTip="Edit article" NavigateUrl='<%# "~/TBSArticles/WriteOrEditArticle.aspx?ID=" + Eval("ID") + "&CatID=" + Eval(this.Request.QueryString["CatID"].ToString()) != ""? this.Request.QueryString["CatID"] : Eval("CategoryID")) %>' ImageUrl="~/Images/Edit.gif"
Any help will be greatly appreciated.
Thanks
© Stack Overflow or respective owner