The easiest way is to use a helper function that trims the text to the
correct length and adds the ellipsis. Here's some code that uses only
the first ten characters, let us know if it helps?
Ken
Microsoft MVP [ASP.NET]
Toronto
<asp:datagrid id="DataGrid1" runat="server"
AutoGenerateColumns="False" PageSize="3">
<columns>
<asp:templatecolumn>
<itemtemplate>
<asp:label runat="server" Text='<%#
FixLongLine(DataBinder.Eval(Container, "DataItem.StringValue")) %>'
ID="Label1">
</asp:label>
</itemtemplate>
</asp:templatecolumn>
</columns>
</asp:datagrid>
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
If Not IsPostBack Then
DataGrid1.DataSource = CreateDataSource()
DataGrid1.DataBind()
End If
End Sub
Public Function FixLongLine(ByVal strIn) As String
If Len(strIn) > 10 Then
Return Left(strIn, 10) & "..."
End If
Return strIn
End Function
Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New DataColumn _
("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = i
dr(1) =
"Itemxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxx
" + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource
Hello,
Im new in asp.net especially in web base application.
I want to ask about datagrid. I had shown my table on
datagrid, and what I want to ask is how to set the column
height fixed? Because when I have a long word it
automatically set new line instead of hide it. I want it
to be hide like this 928192... with 3 dot at the end of
the word if it is to long.
Is it possible to do it?
Thanks alll