This is a migrated thread and some comments may be shown as answers.

Databinding and string concatenating

2 Answers 449 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Morten Louw
Top achievements
Rank 1
Morten Louw asked on 26 Nov 2009, 12:42 PM
Hi all,

Is there anyone with a simple sample for string concatenating in a databinding field...

Here's my case.
I have a RadGrid with a hyperlink column. I want the link to link to a customer, but also to add a querystring parameter called returnurl.
The value of the ReturnUrl is the AbsoluteUri of the page. It can vary by it's QueryString.
A simple thing in many ways. And I could solve this by using the databound events, but I just think that another solution must be possible.

This is one take I tried. ReturnUrl is a public property on the page, returning the AbsoluteUri of the page. I did remember to call DataBind on the page.

<telerik:GridHyperLinkColumn DataTextField="Name" HeaderText="Name"   
UniqueName="ClientName" DataNavigateUrlFields="ID"   
DataNavigateUrlFormatString="clEdit.aspx?clID={0}&amp;returnurl=<%# ReturnUrl   
%>> 

I also tried to make the call directly to the Request.Url.AbsoluteUri in stead of the property.
I also tried with ' in stead of "

So, if anyone has a take on this, please help me :)

Kind regards,
Morten

2 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 30 Nov 2009, 04:04 PM
Hello Morten,

As you already noticed, your expression won't be evaluated in this context. I recommend you either add the URL manually on ItemDataBound:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        HyperLink lb = (e.Item as GridDataItem)["ClientName"].Controls[0] as HyperLink;
        lb.NavigateUrl += Request.Url.AbsoluteUri;
    }
}

...or use GridTemplateColumn instead of GridHyperLinkColumn:
<telerik:GridTemplateColumn ...>
    <ItemTemplate>
        <asp:HyperLink ID="HyperLink1" runat="server" Text='<%# Eval("Name") %>' NavigateUrl='<%# "clEdit.aspx?clID=" + Eval("ID") + "&returnurl=" + Request.Url.AbsoluteUri %>'>
        </asp:HyperLink>
    </ItemTemplate>
</telerik:GridTemplateColumn>

Best regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Morten Louw
Top achievements
Rank 1
answered on 30 Nov 2009, 08:02 PM
Hi Daniel,

Thanks for your answer. I will give it a go tomorrow!

Kind regards,
Morten :)
Tags
Grid
Asked by
Morten Louw
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Morten Louw
Top achievements
Rank 1
Share this question
or