<%# DataBinder.Eval(Container.DataItem, "smalldir")%> 要取这个字段前2位.....怎么写? <%# DataBinder.Eval(Container.DataItem, "smalldir")%> 要取这个字段前2位.....怎么写? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <%# getfirsttwo(DataBinder.Eval(Container.DataItem, "smalldir").ToString())%>后台写函数public string getfirsttwo(string temp){ return temp.Substring(0,2);} <%# ((string)DataBinder.Eval(Container.DataItem, "smalldir")).Substring(0,2)%> <%# ((string)DataBinder.Eval(Container.DataItem, "smalldir")).Substring(0,2)%>这种方法比较简单. <%# ((DataBinder.Eval(Container.DataItem, "smalldir")).ToString().Length>3)?(DataBinder.Eval(Container.DataItem, "smalldir")).ToString().Substring(0,2): DataBinder.Eval(Container.DataItem, "smalldir")%> <%# getfirsttwo(DataBinder.Eval(Container.DataItem, "smalldir").ToString())%>后台写函数public string getfirsttwo(string temp){ return temp.Substring(0,2);} <%#((string)DataBinder.Eval(Container.DataItem,"name")).Substring(0,2)%> 长度不到2为的话会报错,建议在函数中加个判断:<%#getnewstring(DataBinder.Eval(Container.DataItem, "name").ToString())%> public string getnewstring(string wangzhe) { if(wangzhe.Length<2) { return wangzhe; } else { return wangzhe.Substring(0,2); } } 你可以在cs代码里面写一个方法:protected string CutString(string str,int length){ string newString=""; if(str!="") { if(str.Length>length) { newString=str.Substring(0,length)+"..."; } else { newString=str; } } return newString;}然后:<%# CutString(DataBinder.Eval(Container.DataItem,"newtitle").ToString(),10) %> 根据库里面取出来的记录 动态生成select 而不是dropdownlist 急急急!!伪静态发布IIS后访问问题,Help... c# 小數點後無效0不顯示 小问题 我的程序有几个问题. 求助,为什么我的 主程序和 其他的不是在同一个地方呢? 不同的编码输出的页面大小一样吗? 请教一个javascript的问题! 枚举类型数据的查询 应用程序配置文件 菜鸟急问:又是Tree View问题 如何在WEB应用程序中动态创建“数据库链接”,并进行多库间的数据联合查询??
后台写函数
public string getfirsttwo(string temp)
{
return temp.Substring(0,2);
}
这种方法比较简单.
<%# getfirsttwo(DataBinder.Eval(Container.DataItem, "smalldir").ToString())%>
后台写函数
public string getfirsttwo(string temp)
{
return temp.Substring(0,2);
}
<%#getnewstring(DataBinder.Eval(Container.DataItem, "name").ToString())%>
public string getnewstring(string wangzhe)
{
if(wangzhe.Length<2)
{
return wangzhe;
}
else
{
return wangzhe.Substring(0,2);
}
}
protected string CutString(string str,int length)
{
string newString="";
if(str!="")
{
if(str.Length>length)
{
newString=str.Substring(0,length)+"...";
}
else
{
newString=str;
}
}
return newString;
}
然后:
<%# CutString(DataBinder.Eval(Container.DataItem,"newtitle").ToString(),10) %>