Yeah, I guess that would be the easiest way. Thanks, I'll give it a shot.
Aaron
"Ken Cox [Microsoft MVP]" <> wrote in message
news:...
> Hi Aaron,
>
> Just add in a check for the item type so that it only looks at regular
rows,
> not the header or footer:
>
> Private Sub DataGrid1_ItemDataBound _
> (ByVal sender As Object, _
> ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) _
> Handles DataGrid1.ItemDataBound
> If e.Item.ItemType = ListItemType.AlternatingItem Or _
> e.Item.ItemType = ListItemType.Item Then
> e.Item.Cells(0).Text = Left(e.Item.Cells(0).Text, 10)
> End If
> End Sub
>
> Ken
>
> "Aaron" <> wrote in message
> news:%...
> > Yes, this helps, but it is also perfoming this function on the column
> > headers. Is there any way to prevent this?
> > Thanks,
> > Aaron
> >
> >
> > "Ken Cox [Microsoft MVP]" <> wrote in message
> > news:ecJvu%...
> >> Hi Aaron,
> >>
> >> During the ItemDataBound event, you get a reference to the row that is
> >> getting data. At that time you can get a reference to the cell's text
and
> >> take the Left 25 characters. Some code to show this is below.
> >>
> >> Let us know if this helps?
> >>
> >> Ken
> >> Microsoft MVP [ASP.NET]
> >> Toronto
> >>
> >>
> >> Private Sub Page_Load _
> >> (ByVal sender As System.Object, _
> >> ByVal e As System.EventArgs) _
> >> Handles MyBase.Load
> >> If Not IsPostBack Then
> >> Dim Activity_Notes As New BoundColumn
> >> With Activity_Notes
> >> .DataField = "Activity_Notes"
> >> .HeaderText = "Notes"
> >> End With
> >> DataGrid1.Columns.Add(Activity_Notes)
> >> DataGrid1.DataSource = CreateDataSource()
> >> DataGrid1.AutoGenerateColumns = False
> >> DataGrid1.DataBind()
> >> End If
> >> End Sub
> >> 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 _
> >> ("Activity_Notes", 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) =
> >>
> >
"Itemxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxx
> >> " + i.ToString()
> >> dr(2) = 1.23 * (i + 1)
> >> dr(3) = (i = 4)
> >> dt.Rows.Add(dr)
> >> Next i
> >> Return dt
> >> End Function 'CreateDataSource
> >>
> >>
> >> Private Sub DataGrid1_ItemDataBound _
> >> (ByVal sender As Object, _
> >> ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) _
> >> Handles DataGrid1.ItemDataBound
> >> e.Item.Cells(0).Text = Left(e.Item.Cells(0).Text, 25)
> >> End Sub
> >>
> >> "Aaron" <> wrote in message
> >> news:e54%...
> >> >I am programmatically adding columns to my datagrid and that is
working
> >> >very
> >> > well.
> >> > I am using this code to add the column:
> >> > Dim Activity_Notes As New BoundColumn()
> >> > With Activity_Notes
> >> > .DataField = "Activity_Notes"
> >> > .HeaderText = "Notes"
> >> > End With
> >> > datagrid.columns.add(Activity_Notes)
> >> > datagrid.bind()
> >> >
> >> > The data in this cell is very long, and I wish to only display the
> >> > first
> >> > 25
> >> > chars. What is the best way to do this?
> >> >
> >> > I do not want to only select the first 25 chars from sql...
> >> >
> >> > Thanks,
> >> > Aaron
> >> >
> >> >
> >>
> >
> >
>
|