我在模板列中取了两个字段,我想将这两个字段合并之后再截取长度
<asp:TemplateField HeaderText="第一列">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("sid","~/show.aspx?id={0}") %>' Target="_blank"><%# DataBinder.Eval(Container.DataItem, "s1", "{0}")%><%# DataBinder.Eval(Container.DataItem, "s2", "{0}")%></asp:HyperLink>
</ItemTemplate>
<ItemStyle Width="140px" />
</asp:TemplateField>我本来想在后台这样写的
e.Row.Cells[1].Text = dbcode.getstr(e.Row.Cells[1].Text, 15); //dbcode.getstr是一个截取方法
但这样写取出来就变成空的了求教一下啊
<asp:TemplateField HeaderText="第一列">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("sid","~/show.aspx?id={0}") %>' Target="_blank"><%# DataBinder.Eval(Container.DataItem, "s1", "{0}")%><%# DataBinder.Eval(Container.DataItem, "s2", "{0}")%></asp:HyperLink>
</ItemTemplate>
<ItemStyle Width="140px" />
</asp:TemplateField>我本来想在后台这样写的
e.Row.Cells[1].Text = dbcode.getstr(e.Row.Cells[1].Text, 15); //dbcode.getstr是一个截取方法
但这样写取出来就变成空的了求教一下啊
解决方案 »
- 怎么用js判断repeater中textbox是否为空
- 求高手解释
- Gridview排序时如何分页也同样排序?
- 你们一般是用label保存值还是在后台用变量啊?
- 一个SQL 存储过程中 有 select 语句 也有 insert、update、语句。
- 100分求助:如何在DataList里要显示两个DataSource的东西怎么办?
- web程序的2个控件绑定sqlserver后,无法实现游标功能,求助!
- 把一个网站设为IIS的默认网站后其他虚拟目录访问则报错
- 在线给分,兄弟们请救救我!datagrid问题
- 如何动态设置datagrid的某列的readonly=true这个属性?
- 小生不才 问个语句
- *************Float类型的问题
e.Row.Cells[1].Text = dbcode.getstr(a, 15);
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" Target="_blank"><%#( Eval ( "s1" ).ToString () + Eval ( "s2" ).ToString () ).Substring ( 0, 15 )%></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
{
if (original == null)
{
return null;
} int originalLength = original.Length;
int calucateLength = 0;
int lastCharLength = 0;
System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(@"[^\x00-\xff]"); for (int i = 0; i < originalLength; i++)
{
int thisCharLength = 0;
if (reg.Match(original, i, 1).Success)
{
calucateLength += 2;
thisCharLength = 2;
}
else
{
calucateLength += 1;
thisCharLength = 1;
}
//如果超过了长度限制,就将当前字符和上一个字符去掉,同时要考虑,如果上一个字符为全角,就只取一个
//如果为半角就去两个
if (calucateLength > leftLength * 2)
{
return original.Substring(0, i - (lastCharLength == 1 ? 2 : 1)) + "..";
}
lastCharLength = thisCharLength;
}
return original;
}
你直接使用cutoff(你的数据,长度)就可以了