Rickshaw
Rickshaw

Reputation: 107

Append text in GridView DataFields

I'm trying to append text in my ASP DataField:

<asp:BoundField  DataField='"https://media.expedia.com" + thumbNailUrl' HeaderText="Image" />

However, this is not working. Is there any other way to do this?

Upvotes: 0

Views: 573

Answers (2)

j.v.
j.v.

Reputation: 997

<asp:BoundField DataField="thumbNailUrl" HeaderText="Image" />       

protected void OnRowDataBound(object sender, EventArgs e)
{
    var ea = e as GridViewRowEventArgs;
    if (ea.Row.RowType == DataControlRowType.DataRow)
    {
        var d = ea.Row.DataItem as DataRowView;
        var ob = d["thumbNailUrl"];
        if (!Convert.IsDBNull(ob))
        {
            var cell = ea.Row.Cells[x];
            cell.Text = String.Format("https://media.expedia.com{0}", ob.ToString());
        }
    }
}

Upvotes: 2

VDWWD
VDWWD

Reputation: 35544

Use the DataFormatString

<asp:BoundField DataField="thumbNailUrl" DataFormatString="https://media.expedia.com/{0}" HeaderText="Image" />

Upvotes: 4

Related Questions