1. Place the code in sqlhelper.
Copy codeThe Code is as follows:
# Region truncated string
/// <Summary>
/// Capture a string
/// </Summary>
/// <Param name = "str_value"> </param>
/// <Param name = "str_len"> </param>
/// <Returns> </returns>
Public static string leftx (string str_value, int str_len)
{
Int p_num = 0;
Int I;
String New_Str_value = "";
If (str_value = "")
{
New_Str_value = "";
}
Else
{
Int Len_Num = str_value.Length;
For (I = 0; I <= Len_Num-1; I ++)
{
If (I> Len_Num) break;
Char c = Convert. ToChar (str_value.Substring (I, 1 ));
If (int) c> 255) | (int) c <0 ))
P_num = p_num + 2;
Else
P_num = p_num + 1;
If (p_num> = str_len)
{
New_Str_value = str_value.Substring (0, I + 1 );
Break;
}
Else
{
New_Str_value = str_value;
}
}
}
Return New_Str_value;
}
# Endregion
2. Foreground call:
Copy codeThe Code is as follows:
<% # UserInfo. DAL. SqlHelper. leftx (DataBinder. Eval (Container. DataItem, "Title"). ToString (), 20) %>