怎么控制模板(Repeater)中的字数? 用模板绑定了数据,想控制字数在4个以内,如果大于4个字则多余的字显示成"...",若小于4个字则全部显示. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 /// <summary> /// 字符拆分处理 /// </summary> /// <param name="strTemp">数据源</param> /// <param name="intLen">拆取的长度</param> /// <param name="AddPoint">是否加在后面加"...",为true则添加,否则不添加</param> /// <returns></returns> public string SubstringLength(string strTemp,int intLen, bool AddPoint) { string strApp = ""; int strLength = System.Text.Encoding.Default.GetBytes(strTemp).Length; if (strLength > intLen) { strApp = strTemp.Substring(0, intLen); if (AddPoint == true) strApp += "..."; } else { strApp = strTemp.ToString(); } //****返回重新构造的字符 return strApp; }//****调用函数<%#SubstringLength(DataBinder.Eval(Container.DataItem,"Context").ToString(),4,true)%>//****第二种方法用SQLSELECT *,CASE WHEN LEN(CONTEXT)>4 THEN SUBSTRING(CONTEXT,0,4)+'...' ELSE CONTEXT END AS CONTEXTNAME FROM TB_INFO 是在ASP.NET中写这个函数吗?有在HTML绑定的时候做判断的吗? 我记得好像css2.0里有这个功能 你参考一下下面的代码吧<html xmlns:rdl><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>Rainer's Handbook</title><style>body{margin:0px;padding:12px;background:#FFFFFF;overflow:auto;}body,table,input,select,textarea,a{font-family:verdana,tahoma,arial;font-size:11px;color:#000000;word-break:break-all;}table,img{border:0px;}a{text-decoration:none;color:#003399;}a:hover{color:#000000;text-decoration:underline;}#id_div3{padding-top:8px;border-top:1px solid #000000;line-height:15px;}#id_span3{font-size:10px;font-family:tahoma;}</style><style>#idDIV{width:100%;height:90px;background-color:#87CEEB;padding:8px;overflow:hidden; text-overflow:ellipsis;white-space:nowrap; }#idCodeDiv{width:100%;padding:4px;font-family:verdana,tahoma;margin:12px 0px 0px 0px;background-color:#EEEEEE;font-weight:bold;}</style><script>function rdl_change(e){var oCodeDiv=document.all("idCodeDiv");var oDiv=document.all("idDiv");with (document.all("idSel1")) var sValue1=options[selectedIndex].value;with (document.all("idSel2")) var sValue2=options[selectedIndex].value;with (oDiv.style) {overflow=sValue1;textOverflow=sValue2;}oCodeDiv.innerText="overflow : "+sValue1+"\r\n"+"text-overflow : "+sValue2+" ;";}</script></head><body><div id=idDIV>请您从下面的选择框中选择这段文字的相应属性的值。看一看会发生什么,然后您就会明白他们的意义。</div><br><table><tr><td><select id="idSel1" onchange="rdl_change();"><option value="hidden">---overflow---<option value="hidden">hidden<option value="visible">visible</select></td><td><select id="idSel2" onchange="rdl_change();"><option value="clip">---text-overflow---<option value="clip">clip<option value="ellipsis" selected>ellipsis</select></td></tr></table><div id=idCodeDiv>overflow : ellipsis ;<br>text-overflow : hidden ;</div><br> <br> <br><div id=id_div3>苏昱作品·版权所有<br><span id=id_span3>©2002 Rainer Su . All rights reserved .</span></div></body></html> Re:弹出错误“SubstringLength”方法没有采用“1”个参数的重载因为绑定的是一个字段,函数中的参数为三个.....//*****将下面的函数写在后台,然后在前台调用即可./// <summary> /// 字符拆分处理 /// </summary> /// <param name="strTemp">数据源</param> /// <param name="intLen">拆取的长度</param> /// <param name="AddPoint">是否加在后面加"...",为true则添加,否则不添加</param> /// <returns></returns> public string SubstringLength(string strTemp,int intLen, bool AddPoint) { string strApp = ""; int strLength = System.Text.Encoding.Default.GetBytes(strTemp).Length; if (strLength > intLen) { strApp = strTemp.Substring(0, intLen); if (AddPoint == true) strApp += "..."; } else { strApp = strTemp.ToString(); } //****返回重新构造的字符 return strApp; }//****例子 <asp:Repeater ID="RepList" runat="server"> <ItemTemplate> <table border="0" cellpadding="0" cellspacing="0"> <tr> <td> 企业名称:</td> <td> <!--调用后台函数 --> <%#SubstringLength(DataBinder.Eval(Container.DataItem, "CopationName").ToString(),4,true)%> </td> </tr> <tr> <td colspan="2"> <asp:Repeater ID="ChileReption" runat="server" DataSource='<%#((DataRowView)Container.DataItem).Row.GetChildRows("myparent")%>'> <ItemTemplate> <table border="0" cellpadding="0" cellspacing="0"> <tr> <td> 产口名称:</td> <td> <%#DataBinder.Eval(Container.DataItem,"[\"ProductName\"]")%> </td> <td> 单价:</td> <td> <%#DataBinder.Eval(Container.DataItem,"[\"Proice\"]","{0:c}")%> </td> </tr> </table> </ItemTemplate> </asp:Repeater> </td> </tr> </table> </ItemTemplate> </asp:Repeater> 如何在后台取出前台select控件的选中值 FAXCOMLib 发送传真怎么判断发送状态 word与mht之间的转换 datagrid里的linkbutton为什么点击两次才会激发事件? 客户端用JS改变了ListBox的Item后,提交回服务器端后C#读不到 关于owc图例的问题,急用 怎样对Dll进行签名(无源码) RSA 解密问题,急,在线等 谁能提供一个最简单的程序:一个界面(至少6个不同控件),并把取的值插入到数据库中(什么数据库都行)? 如何从datagrid中取出被编辑字段的内容(还没有保存) 安装TreeView控个问题 关于CHECKBOX和TREEVIEW的问题
/// 字符拆分处理
/// </summary>
/// <param name="strTemp">数据源</param>
/// <param name="intLen">拆取的长度</param>
/// <param name="AddPoint">是否加在后面加"...",为true则添加,否则不添加</param>
/// <returns></returns>
public string SubstringLength(string strTemp,int intLen, bool AddPoint)
{
string strApp = ""; int strLength = System.Text.Encoding.Default.GetBytes(strTemp).Length; if (strLength > intLen)
{
strApp = strTemp.Substring(0, intLen);
if (AddPoint == true) strApp += "...";
}
else
{
strApp = strTemp.ToString();
} //****返回重新构造的字符
return strApp;
}//****调用函数
<%#SubstringLength(DataBinder.Eval(Container.DataItem,"Context").ToString(),4,true)%>//****第二种方法用SQL
SELECT *,CASE WHEN LEN(CONTEXT)>4 THEN SUBSTRING(CONTEXT,0,4)+'...' ELSE CONTEXT END AS CONTEXTNAME FROM TB_INFO
有在HTML绑定的时候做判断的吗?
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Rainer's Handbook</title>
<style>
body{margin:0px;padding:12px;background:#FFFFFF;overflow:auto;}
body,table,input,select,textarea,a{font-family:verdana,tahoma,arial;font-size:11px;color:#000000;word-break:break-all;}
table,img{border:0px;}
a{text-decoration:none;color:#003399;}
a:hover{color:#000000;text-decoration:underline;}
#id_div3{padding-top:8px;border-top:1px solid #000000;line-height:15px;}
#id_span3{font-size:10px;font-family:tahoma;}
</style>
<style>
#idDIV{width:100%;height:90px;background-color:#87CEEB;padding:8px;overflow:hidden; text-overflow:ellipsis;white-space:nowrap; }
#idCodeDiv{width:100%;padding:4px;font-family:verdana,tahoma;margin:12px 0px 0px 0px;background-color:#EEEEEE;font-weight:bold;}
</style><script>
function rdl_change(e){
var oCodeDiv=document.all("idCodeDiv");
var oDiv=document.all("idDiv");
with (document.all("idSel1")) var sValue1=options[selectedIndex].value;
with (document.all("idSel2")) var sValue2=options[selectedIndex].value;
with (oDiv.style) {
overflow=sValue1;textOverflow=sValue2;
}
oCodeDiv.innerText="overflow : "+sValue1+"\r\n"+"text-overflow : "+sValue2+" ;";
}
</script></head>
<body>
<div id=idDIV>请您从下面的选择框中选择这段文字的相应属性的值。看一看会发生什么,然后您就会明白他们的意义。</div>
<br>
<table><tr><td>
<select id="idSel1" onchange="rdl_change();">
<option value="hidden">---overflow---
<option value="hidden">hidden
<option value="visible">visible
</select>
</td><td>
<select id="idSel2" onchange="rdl_change();">
<option value="clip">---text-overflow---
<option value="clip">clip
<option value="ellipsis" selected>ellipsis
</select>
</td></tr></table>
<div id=idCodeDiv>overflow : ellipsis ;<br>text-overflow : hidden ;</div><br> <br> <br>
<div id=id_div3>苏昱作品·版权所有<br><span id=id_span3>©2002 Rainer Su . All rights reserved .</span></div>
</body>
</html>
因为绑定的是一个字段,函数中的参数为三个.....//*****将下面的函数写在后台,然后在前台调用即可./// <summary>
/// 字符拆分处理
/// </summary>
/// <param name="strTemp">数据源</param>
/// <param name="intLen">拆取的长度</param>
/// <param name="AddPoint">是否加在后面加"...",为true则添加,否则不添加</param>
/// <returns></returns>
public string SubstringLength(string strTemp,int intLen, bool AddPoint)
{
string strApp = ""; int strLength = System.Text.Encoding.Default.GetBytes(strTemp).Length; if (strLength > intLen)
{
strApp = strTemp.Substring(0, intLen);
if (AddPoint == true) strApp += "...";
}
else
{
strApp = strTemp.ToString();
} //****返回重新构造的字符
return strApp;
}
//****例子 <asp:Repeater ID="RepList" runat="server">
<ItemTemplate>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
企业名称:</td>
<td>
<!--调用后台函数 -->
<%#SubstringLength(DataBinder.Eval(Container.DataItem, "CopationName").ToString(),4,true)%>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Repeater ID="ChileReption" runat="server" DataSource='<%#((DataRowView)Container.DataItem).Row.GetChildRows("myparent")%>'>
<ItemTemplate>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
产口名称:</td>
<td>
<%#DataBinder.Eval(Container.DataItem,"[\"ProductName\"]")%>
</td>
<td>
单价:</td>
<td>
<%#DataBinder.Eval(Container.DataItem,"[\"Proice\"]","{0:c}")%>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>