Tuesday, January 27, 2009

How to concatenate two values while binding in Gridview/Datagrid?

You can only have 1 databinding expression ( <%# xxx %> ) so you have to concatenate it:
Text='<%# Eval("Views") + Eval("ViewsAll","({0})") %>'
or another way (which I personally prefer) is to let a code behing method deal with it:
Text='<%# FormatViews(Eval("Views"),Eval("ViewsAlL")) %>'
and then in code behind

protected string FormatViews(object views, object viewsAll)
{
return String.Format("{0} ({1})",views,viewsAll);
}

No comments:

 
Feedback Form