日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Eval 数据绑定

發布時間:2024/1/17 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Eval 数据绑定 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

<%# Regex.Replace((string)Eval("IP"), @"\.\d+$", ".*") %>?

Eval內部必須是雙引號,因為它是普通的c#方法。 Eval可以使用第二個參數格式化,因此例如你就可以寫: <%# Eval("ID","~/DelegateConfirm.aspx?id={0}") %> <%# 表達式%>---------<%#sum/10 %> Barcode字段存儲的是條形碼號,如果條形號碼為空,則顯示"待審核",否則顯示條形碼 <%#Eval("Barcode").Equals("") ? "<font color='red'>待審核</font>" : "<img src='http://www.mywebsite.com/barcode/barcode.dll?id="+Eval("Barcode")+"'/>"%> 將格式化日期的方法綁定到數據控件中 protected string GetTime(object time) { return Convert.ToDateTime(time).ToString("yyyy-MM-dd", System.Globalization.DateTimeFormatInfo.InvariantInfo); } 然后,將自定義方法GetTime,綁定到數據控件GridView中的顯示日期列上,其代碼如下: <%# GetTime(DataBinder.Eval(Container.DataItem, "POSTTIME"))%> 格式化時間并進行綁定 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( ); } 高亮: public static string HighLight(string instr, bool light) { if (light) { instr = "<span style='color:red'>" + instr + "</span>";//要加亮的文本,Red } else { instr = "<span style='color:blue'>" + instr + "</span>";//要加亮的文本,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("未審核", true);//Red } else { e.Row.Cells[4].Text = HighLight("已審核", false);//Blue } } }

?
int 遇到 null :

?<td?align="center">
<%
#?Eval("SpecAppend.Result3")?==?null???"<font?color='#ff0066'>未返回</font>"?:?
Convert.ToInt32(Eval(
"SpecAppend.Result3"))?==?2???"<font?color='red'>失敗</font>"?:?
"<font?color='blue'>成功</font>" ?%></td>??


避免Object cannot be cast from DBNull to other types. 錯誤

??<%# Eval("Sex").GetType() == Type.GetType("System.DBNull") ?"未設置": Convert.ToInt32(Eval("Sex")).Equals(0)?"<font color='blue'>女</font>" : "<font color='green'>男</font>"%>

?

?ImageUrl='<%#?"../HotShopImg/"+DataBinder.Eval(Container.DataItem,"ImgURL")?%>'


------Eval("picture").ToString()----記得加").ToString() 不然會提示object無法轉換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+$", ".*") %>

?

//?????隱藏IP。
//?????參數:
//?????ip?:?需要隱藏的IP。
//?????n??:?隱藏的位數。
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);? 結果 192.168.0.*?
Text.IP("192.168.0.1", 2);? 結果 192.168.*.*?
Text.IP("192.168.0.1", 3);? 結果 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()) %>??

?

使用Eval數據綁定時提示:字符文本中的字符太多

錯誤的? Text="<%# Eval('ProductID') %>">

正確的? Text='<%# Eval("ProductID") %>'>

?

總結

以上是生活随笔為你收集整理的Eval 数据绑定的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。