Click here to Skip to main content
15,885,886 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Expert,


I am developing c sharp application.

Now i am showing database results in Listview.

Like following,
C#
<%# Eval("category1")%>
<%# Eval("category2")%>
<%# Eval("category3")%> 



Now I have to concat above 3 results with semicolumn separator and substring starting from 0 to 45.

How i can achieve like this.


Thanksssssssss in advance.
Posted
Updated 22-Sep-11 18:27pm
v2

Hi
string.Format("{0},{1},{2}",Eval("category1"),Eval("category2"),Eval("category3")).Substring(0,45)
 
Share this answer
 
Comments
udusat13 23-Sep-11 0:34am    
Thanksssssssssssssssssss

But
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.



this exception was thrown;
please help me.
kris444 23-Sep-11 0:43am    
oops...
ok, what i suggest is have a property like

public string Categeory
{
get
{
string catText = string.Format("{0},{1},{2}", category1, category2, category3);
return catText.Length > 45 ? catText.Substring(0, 45) : catText;
}
}
and bind
<%= Eval("Categeory")>
udusat13 23-Sep-11 1:03am    
thanksssssssssss for ur valuable time.

But still it giving same exception as above
kris444 23-Sep-11 1:06am    
Hmmm....when you bind property of type string, it shouldn't give the same issue..

You added property in code-behind right?
and added

<%# Eval("Categeory")%> ?
udusat13 23-Sep-11 1:17am    
thnksssss.
i have added the property code in code behind page.


and
<%# Eval("Categeory")%>
above line is added in listview.

then i start to tracing using breakpont but
<%# Eval("Categeory")%>

this line throw exception.

for simple
<%# Eval("categeory1")%><%,%> <%# Eval("categeory1")%><%,%> <%# Eval("categeory1")%>
working for me.but then it is problem to find substring.
Concatenation operator & is used to solve this problem

HTML
<![CDATA[<%= Eval("category1") & ";" & Eval("category2") & ";" & Eval("category3")%>]]>
 
Share this answer
 
Comments
udusat13 23-Sep-11 0:44am    
Thanksssssssssssssssssss But Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control. this exception was thrown;

please help me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900