<% # RegEx. Replace (string) eval ("ip"), @ "\. \ D + $", ". *") %>
The eval must be enclosed in double quotation marks because it is a common C # method. Eval can be formatted using the second parameter. For example, you can write: <% # eval ("ID ","~ /Delegateconfirm. aspx? Id = {0} ") %> <% # expression %> --------- <% # sum/10%> the barcode field stores the barcode number. If the bar number is empty, "To be reviewed" is displayed; otherwise, the bar code <% # eval ("barcode") is displayed "). equals ("")? "<Font color = 'red'> to be reviewed </font>": " "%> bind the method for formatting the date to the protected string gettime (Object time) {return convert. todatetime (time ). tostring ("yyyy-mm-dd", system. globalization. datetimeformatinfo. invariantinfo);} Then, bind the custom method gettime to the display date column in the Data Control gridview. The Code is as follows: <% # gettime (databinder. eval (container. dataitem, "posttime") %> Format the time and bind it to for (INT I = 0; I <= gridview1.rows. count-1; I ++) {datarowview DRV = Ds. tables ["tborder"]. defaultview [I]; datetime dt = convert. todatetime (DRV ["edate"]); gridview1.rows [I]. cells [9]. TEXT = DT. tolongdatestring ();} highlighted: public static string highlight (string instr, bool light) {If (light) {instr = "<span style = 'color: red '> "+ instr +" </span> "; // text to be highlighted, red} else {instr =" <span style = 'color: blue '> "+ instr +" </span> "; // text to be highlighted, blue} return instr;} protected void gridview1_rowdatabound (Object sender, gridviewroweventargs E) {If (E. row. rowtype = datacontrolrowtype. datarow) {If (E. row. cells [4]. TEXT = "false") {e. row. cells [4]. TEXT = highlight ("not reviewed", true); // red} else {e. row. cells [4]. TEXT = highlight ("reviewed", false); // blue }}}
Int encounters NULL:
<TD align = "center">
<% # Eval ("specappend. result3") = NULL? "<Font color = '# ff0066'> not returned </font> ":
Convert. toint32 (eval ("specappend. result3") = 2? "<Font color = 'red'> failed </font> ":
"<Font color = 'blue'> Successful </font>" %> </TD>
Avoid object cannot be cast from dbnull to other types. Error
<% # Eval ("sex"). GetType () = type. GetType ("system. dbnull ")? "Not set": Convert. toint32 (eval ("sex"). Equals (0 )? "<Font color = 'blue'> female </font>": "<font color = 'green'> male </font>" %>
Imageurl = '<% # "../hotshopimg/" + databinder. eval (container. dataitem, "imgurl") %>'
------ Eval ("picture"). tostring () ---- remember to add "). tostring () Otherwise, the system will prompt that the object cannot be converted to string.
<A href = '<% # databinder. eval (container. dataitem, "url") %>'>
<Asp: Image id = "image1" runat = "server" imageurl = '<% # eval ("picture"). Equals ("")? "Http://www.princehall.com.cn/img/no_img.gif ":
Eval ("picture"). tostring (). substring (0, Eval ("picture"). tostring (). lastindexof (".") + "C"
+ Eval ("picture "). tostring (). substring (eval ("picture "). tostring (). lastindexof (". ") %> '/> </a>
TEXT = '<% # BIND ("price0", "{0: N2}") %>'
IP: 1.1.1.1 --- 1.1.1 .*
<% # RegEx. Replace (string) eval ("ip"), @ "\. \ D + $", ". *") %>
// Hide the IP address.
// Parameters:
// Ip: the IP address to be hidden.
// N: the number of hidden digits.
Public static string IP (string IP, int N)
{
If (string. isnullorempty (IP ))
{
Return string. empty;
}
String [] ary = IP. Split ('.');
Int length = text. getarraylength (ary );
String result = ary [0];
For (INT I = 1; I <length; I ++)
{
If (I + 1> length-N)
{
Result = Result + ".*";
}
Else
{
Result = Result + "." + ary [I];
}
}
Return result;
}
Text. IP ("192.168.0.1", 1); Result 192.168.0 .*
Text. IP ("192.168.0.1", 2); Result 192. 168 .*.*
Text. IP ("192.168.0.1", 3); Result 192 .*.*.*
Public String strphone (string phone)
{String Reg = phone. substring (phone. Length-8, 5); phone = phone. Replace (Reg, "*****"); return phone ;}
137*432 <% # strphone (eval ("phone"). tostring () %>
When using eval data binding, the system prompts: too many characters are in the character text
Incorrect text = "<% # eval ('produd D') %>">
Correct text = '<% # eval ("productid") %>'>