62,046
社区成员
发帖
与我相关
我的任务
分享
public static string FixLenB(string strContent,int sLen)
{
//超过规定长度加上“…”
byte[] s1 = System.Text.Encoding.Default.GetBytes(strContent);
int tLen=sLen+2; //规定长度加上“…”的总长度
//若转换为字节的字符串的长度小于指定的长度加上“...”的总长度则执行
if(s1.Length<=tLen)
{
return strContent;
}
else
{
strContent=System.Text.Encoding.Default.GetString(s1,0,sLen)+"…";;
return strContent;
}
}
<asp:HyperLink ID="HyperLink2" runat="server" Font-Size="Small" Height="80px" Width="483px" Text='<% FixLenB(Eval("Production_purpose").ToString(),100)%>' NavigateUrl='<%# "DataListInfo.aspx?UID=" + DataBinder.Eval(Container.DataItem,"Production_id") %>'>[HyperLink2]</asp:HyperLink>
public void DataListBind()
{
try
{
int StartIndex = CurrentPage * PageSize;//设定导入的起终地址
string sql = "select a.fileContext,b.Production_Name,b.Production_id,b.type,b.Production_purpose from [File] as a,Production as b where b.Production_id=a.ID ";
my_DataBase.SqlConnection_Open();
SqlDataAdapter sda = new SqlDataAdapter(sql,my_DataBase.conn);
sda.Fill(ds, StartIndex, PageSize, "Production");//这是sda.Fill方法的第一次重载,里面的变量分别是数据集DataSet ,开始记录数StartRecord,最大的记录数MaxRecord,数据表名TableName
string str = "";
string str1 = "";
str= FixLenB(ds.Tables[0].Rows[0][4].ToString(), 100);
str1=ds.Tables[0].Rows[0][4].ToString();
str1 = str;
this.ProList.DataSource = ds.Tables["Production"].DefaultView;
this.ProList.DataBind();
this.PreviousLB.Enabled = true;
this.NextLB.Enabled = true;
if (CurrentPage == (PageCount - 1)) this.NextLB.Enabled = false;//当为最后一页时,下一页链接按钮不可用
if (CurrentPage == 0) this.PreviousLB.Enabled = false;//当为第一页时,上一页按钮不可用
this.CurrentLbl.Text = (CurrentPage + 1).ToString();//当前页数
my_DataBase.connection_close();
}
catch (Exception ex)
{
Response.Write("<script>alert('The System It's Error!')</script>");
}
}
public static string FixLenB(string strContent,int sLen)
{
//超过规定长度加上“…”
byte[] s1 = System.Text.Encoding.Default.GetBytes(strContent);
int tLen=sLen+2; //规定长度加上“…”的总长度
//若转换为字节的字符串的长度小于指定的长度加上“...”的总长度则执行
if(s1.Length<=tLen)
{
return strContent;
}
else
{
strContent=System.Text.Encoding.Default.GetString(s1,0,sLen)+"…";;
return strContent;
}
}
但没效.因为我是在页面的时候用data.eval绑定这个hayperlink的 public void DataListBind()
{
try
{
int StartIndex = CurrentPage * PageSize;//设定导入的起终地址
string sql = "select a.fileContext,b.Production_Name,b.Production_id,b.type,b.Production_purpose from [File] as a,Production as b where b.Production_id=a.ID ";
my_DataBase.SqlConnection_Open();
SqlDataAdapter sda = new SqlDataAdapter(sql,my_DataBase.conn);
sda.Fill(ds, StartIndex, PageSize, "Production");//这是sda.Fill方法的第一次重载,里面的变量分别是数据集DataSet ,开始记录数StartRecord,最大的记录数MaxRecord,数据表名TableName
string str = "";
this.ProList.DataSource = ds.Tables["Production"].DefaultView;
this.ProList.DataBind();
this.PreviousLB.Enabled = true;
this.NextLB.Enabled = true;
if (CurrentPage == (PageCount - 1)) this.NextLB.Enabled = false;//当为最后一页时,下一页链接按钮不可用
if (CurrentPage == 0) this.PreviousLB.Enabled = false;//当为第一页时,上一页按钮不可用
this.CurrentLbl.Text = (CurrentPage + 1).ToString();//当前页数
my_DataBase.connection_close();
}
catch (Exception ex)
{
Response.Write(" <script> alert('The System It's Error!') </script> ");
}
}