This is a migrated thread and some comments may be shown as answers.

Change dataitem on ItemDataBound

1 Answer 303 Views
Grid
This is a migrated thread and some comments may be shown as answers.
TSCGlobal
Top achievements
Rank 1
TSCGlobal asked on 27 May 2010, 07:05 PM

The problem is a fairly straight foward one, or so I thought.  On the ItemDatabound event, I need to check the value of a certain column of the DataItem.  If the data starts with "PTC" then I need to change the data for that column to read "New Order" instead.  I thought I had it figured out, but it didn't work.  I am assuming it's a simple fix, if someone can take a quick look at it.  Here's the codebehind;

    Private Sub rgPoOrders_ItemDataBound(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rgPoOrders.ItemDataBound  
 
        Dim TrackURL As String 
        Dim Track As New PackageTrack  
 
        If TypeOf e.Item Is GridDataItem Then 
            Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)  
            Dim TrackNum As String = String.Empty  
            Dim SubmittedBy As String = String.Empty  
 
            'assign tracking number to variable  
            If item.OwnerTableView Is rgPoOrders.MasterTableView Then 
                TrackNum = item("cshortrmk").Text  
                SubmittedBy = item("SubmittedBy").Text  
            End If 
 
            'Get URL for tracking number  
            TrackURL = Track.Track(TrackNum)  
 
            'Set Hyperlink variable/control, and URL to hyperlink control  
            'NOTE: UPS has to open separate browser window.  
            Dim TrackButton As HyperLink = DirectCast(item("hlTrackButton").Controls(0), HyperLink)  
            TrackButton.NavigateUrl = TrackURL  
            TrackButton.Target = "_blank" 
 
            'Get Submitted by column, substitute .txt files for data  
            If SubmittedBy.StartsWith("PTC") = True Then 
                SubmittedBy = "New Order" 
            End If 
 
        End If 
    End Sub 

Grid .aspx code:
<telerik:RadGrid ID="rgPoOrders" runat="server" DataSourceID="dsPurchaseOrders"   
    GridLines="None" AllowFilteringByColumn="True" AllowPaging="True"   
    AllowSorting="True" PageSize="25">  
    <MasterTableView ItemStyle-HorizontalAlign="Center" AutoGenerateColumns="False"   
        Width="95%" DataKeyNames="cpono" DataSourceID="dsPurchaseOrders"   
        GridLines="Horizontal" AlternatingItemStyle-HorizontalAlign="Center"   
        HeaderStyle-HorizontalAlign="Center" PagerStyle-PageButtonCount="15">  
        <RowIndicatorColumn> 
            <HeaderStyle Width="20px" /> 
        </RowIndicatorColumn> 
        <ExpandCollapseColumn> 
            <HeaderStyle Width="20px" /> 
        </ExpandCollapseColumn> 
        <Columns> 
            <telerik:GridBoundColumn DataField="cpono" HeaderText="PO #" ReadOnly="True"   
                SortExpression="cpono" UniqueName="cpono">  
            </telerik:GridBoundColumn> 
            <telerik:GridBoundColumn DataField="cconfirmto" HeaderText="Submitted By" 
                ReadOnly="true" UniqueName="SubmittedBy" > 
            </telerik:GridBoundColumn>   
            <telerik:GridBoundColumn DataField="DateOnly" DataType="System.DateTime"   
                HeaderText="Date Submitted" SortExpression="DateOnly" UniqueName="DateOnly">  
            </telerik:GridBoundColumn> 
            <telerik:GridBoundColumn DataField="cshortrmk" HeaderText="Tracking #"   
                UniqueName="cshortrmk">  
            </telerik:GridBoundColumn> 
            <telerik:GridHyperLinkColumn Text="Click Here To Track" HeaderText=""    
                UniqueName="hlTrackButton">  
            </telerik:GridHyperLinkColumn> 
        </Columns> 
        <ItemStyle HorizontalAlign="Center" /> 
        <AlternatingItemStyle HorizontalAlign="Center" /> 
        <HeaderStyle HorizontalAlign="Center" /> 
    </MasterTableView> 
</telerik:RadGrid> 

1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 28 May 2010, 07:21 AM
Hello Beemer,

In order to change the cell value for the column, you have to assign new value to that column which is shown below.

 VB.Net
 If SubmittedBy.StartsWith("PTC") = True Then  
    item("SubmittedBy").Text = "New Order"  
 End If  

Regards,
Shinu.



Tags
Grid
Asked by
TSCGlobal
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or