62,074
社区成员
发帖
与我相关
我的任务
分享
<asp:GridView ID="gvdongtai" AutoGenerateColumns="False" runat="server" Width="170px"
GridLines="None" OnRowDataBound="gvdongtai_RowDataBound">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<li><a href='DynamicNews.aspx?DynamicID=<%#Eval("ID")%>' class="c">
<%#Eval("Title")%>
</a></li>
<asp:Label ID="test" runat="server" Visible="false" Text='<%#Eval("Title") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
protected void gvdongtai_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
1种 //string s = e.Row.Cells[0].Text;
//Label mylabel = new Label();
//mylabel = (Label)e.Row.FindControl("Test");
2种//string s = mylabel.Text.Trim();
3种string s = DataBinder.Eval(e.Row.DataItem, "Title").ToString().Trim();
//e.Row.Cells[0].Text = s.Length > 20 ? s.Substring(0, 20) : s.Trim();
}
}
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
/// <summary>
/// Strings 的摘要说明
/// </summary>
public class Strings
{
public Strings()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public static string CutString(string inputString, int len)
{
ASCIIEncoding ascii = new ASCIIEncoding();
int tempLen = 0;
string tempString = "";
byte[] s = ascii.GetBytes(inputString);
for (int i = 0; i < s.Length; i++)
{
if ((int)s[i] == 63)
{
tempLen += 2;
}
else
{
tempLen += 1;
}
try
{
tempString += inputString.Substring(i, 1);
}
catch
{
break;
}
if (tempLen > len)
break;
}
//如果截过则加上半个省略号
byte[] mybyte = System.Text.Encoding.Default.GetBytes(inputString);
if (mybyte.Length > len)
tempString += "…";
return tempString;
}
}
void CustomersGridView_RowDataBound(Object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
// Display the company name in italics.
e.Row.Cells[1].Text = "<i>" + e.Row.Cells[1].Text + "</i>";
}
}