2011-03-08 4 views

답변

5

당신은있는 gridview의 RowDataBound 이벤트를 처리하고과 같이 텍스트의 길이를 줄일 수 있습니다 : 당신이 한 세트의 폭을 가지고있는 유일한 대답을

protected void gvNotes_RowDataBound(object sender, GridViewRowEventArgs e) 
{ 
    if (e.Row.RowIndex < 0) 
     return; 

    int _myColumnIndex = 0; // Substitute your value here 

    string text = e.Row.Cells[_myColumnIndex].Text; 

    if (text.Length > 100) 
    { 
     e.Row.Cells[_myColumnIndex].Text = text.Substring(0, 100); 
    } 
} 
+0

나는 데이터 바인딩에 문제가 있습니다 : s 당신이 웃을 데이터로 무슨 일이 일어 났는지 볼 수 있다면 요. 내 화면에 데이터를 가져 오는 중 : – SamekaTV

+0

문자열의 크기를 줄이고 싶지 않습니다. 그리드 뷰 – SamekaTV

0

를 익스플로러를 들어, 한, CSS를 사용하여 수 점을 원하지 않으면 오버플로 : 줄임표 또는 오버플로 : 숨김 (모든 브라우저에서 작동)을 설정하십시오.


확인, 주석에 따라, 나는 잠시 동안있는 GridViews을 사용하지 않은,하지만 그 세포의 각각과 클래스의 CSS 클래스를 설정하는 문제가 될 것입니다 :

trimText 
{ 
    overflow:ellipsis; 
} 
또한이 크로스 브라우저를 표시 할 수 할 수있는 해킹 몇 가지있다

- 여기에 몇 가지주의 사항 :

http://www.jide.fr/english/emulate-text-overflowellipsis-in-firefox-with-css

+0

에 데이터의 일부만 표시하면됩니다. 이걸 어떻게 얻을 수 있니? – SamekaTV

0

이 기능을 만들기

public object TrimString(string input, int length) 
    { 
     // return nothing if the string is null 
     if (String.IsNullOrEmpty(input)) 
     { 
      return string.Empty; 
     } 

     // invalid length submitted 
     if (length <= 0) 
     { 
      length = 100; 
     } 

     if (input.Length > length) 
     { 
      return input.Substring(0, length) + "..."; 
     } 

     return input; 
    } 

그리고 당신은 이렇게 aspx 페이지에서 호출합니다.

<ItemTemplate> 
     <asp:Label ID="Label4" runat="server" Text='<%# TrimString(Eval("CustName").ToString(),100) %>'></asp:Label> 
</ItemTemplate> 
관련 문제