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

Passing values in detail view to session variable

1 Answer 388 Views
Grid
This is a migrated thread and some comments may be shown as answers.
TSCGlobal
Top achievements
Rank 1
TSCGlobal asked on 11 Nov 2010, 04:39 PM
Heyas;

I thought I had a fairly straight forward thing going on, but it seems I'm stumbling over syntax.  I am hoping someone can quickly clue me in so I can get this page knocked out.  Basically, I have a grid with a heirarchy.  In the detail view, there's a button that fires the "Select" command.  When that happens, I need to get 2-3 data values from the selected record in the detail, and pass them to a variable for the next step.  I know the code needs to go in the ItemCommand event, but I'm not sure on the syntax.  Most of what I'm trying hasn't really met with much success, and I think it is because I am a little confused how the "bubble up" works when it comes to implementation.

Here's the relevant ASPX code:
<telerik:RadGrid ID="CreditsGrid" runat="server"
    AllowPaging="True"
    AllowSorting="True"
    DataSourceID="SqlDataSource1"
    GridLines="None" AutoGenerateColumns="False">
     
    <MasterTableView
        DataSourceID="SqlDataSource1"
        DataKeyNames="OrderID">
        <DetailTables>
            <telerik:GridTableView runat="server"
                DataSourceID="SqlDataSource2"
                DataKeyNames="OrderID">
            <ParentTableRelation>
                <telerik:GridRelationFields
                    MasterKeyField="OrderID"
                    DetailKeyField="OrderID" />
            </ParentTableRelation>
                <CommandItemSettings ExportToPdfText="Export to Pdf" />
            <Columns>                            
                <telerik:GridBoundColumn
                    DataField="DateCreated"
                    HeaderText="Date Created"
                    SortExpression="DateCreated"
                    UniqueName="DateCreated"
                    ReadOnly="True" />
                <telerik:GridBoundColumn
                    DataField="EnteredBy"
                    HeaderText="Entered By"
                    SortExpression="EnteredBy"
                    UniqueName="EnteredBy"
                    ReadOnly="True" />
                <telerik:GridBoundColumn
                    DataField="ChargeCode"
                    HeaderText="Reason Code"
                    SortExpression="ChargeCode"
                    UniqueName="ChargeCode"
                    ReadOnly="True" />                                   
                <telerik:GridBoundColumn
                    DataField="Description"
                    HeaderText="Description"
                    SortExpression="Description"
                    UniqueName="Description"
                    ReadOnly="True" />
                <telerik:GridButtonColumn
                    Text="Review Transaction"
                    ButtonType="LinkButton"
                    CommandName="Select"
                    UniqueName="btnRevTrans" />                                                                           
            </Columns>
            </telerik:GridTableView>
        </DetailTables>                   
        <RowIndicatorColumn>
            <HeaderStyle Width="20px" />
        </RowIndicatorColumn>
        <CommandItemSettings ExportToPdfText="Export to Pdf" />
        <ExpandCollapseColumn>
            <HeaderStyle Width="20px" />
        </ExpandCollapseColumn>
        <Columns>
            <telerik:GridBoundColumn
                DataField="DateCreated"
                DataType="System.DateTime"
                HeaderText="Date Created"
                SortExpression="DateCreated"
                UniqueName="DateCreated">
                <HeaderStyle Width="175px" />
                <ItemStyle Width="175px" />
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn
                DataField="OrderID"
                DataType="System.Int32"
                HeaderText="OrderID"
                SortExpression="OrderID"
                UniqueName="OrderID">
                <HeaderStyle Width="200px" />
                <ItemStyle Width="200px" />
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn
                DataField="NumOfOrders"
                DataType="System.Int32"
                HeaderText="# of Orders"
                ReadOnly="True"
                SortExpression="NumOfOrders"
                UniqueName="NumOfOrders">
            </telerik:GridBoundColumn>
            <telerik:GridButtonColumn
                CommandName="Select"
                DataTextField="OrderID"
                Text="View"
                UniqueName="column">
            </telerik:GridButtonColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

And following area my feeble attempts on the vb.net side (I know the code is incomplete)
Private Sub CreditsGrid_ItemCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles CreditsGrid.ItemCommand
 
    If e.CommandName = "Select" Then
 
        'Put selected values to variables
        Dim OrderID = CreditsGrid.MasterTableView.GetSelectedItems("OrderID")
        Dim CreatedDate = CreditsGrid.MasterTableView.GetSelectedItems("CreatedDate")
 
        'Removes session variables (just to be safe) & replaces with the new variables.
        Session.Remove("OrderID")
        Session.Remove("CreatedDate")
        Session.Add("OrderID", OrderID)
        Session.Add("CreatedDate", CreatedDate)
 
        'Load Review form.
        CreditsWindow.VisibleOnPageLoad = True
 
    End If
End Sub

Obviously, this doesn't work so well.  Can someone give me a pointer in the right direction?

1 Answer, 1 is accepted

Sort by
0
TSCGlobal
Top achievements
Rank 1
answered on 12 Nov 2010, 03:26 PM
Heyas;

It seems I figured it out.  I'm not sure whether or not this is 'solid' code, but it seems to work.  Here's the vb.net; 

Private Sub CreditsGrid_ItemCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles CreditsGrid.ItemCommand
 
    If e.CommandName = "Select" Then
 
        Dim item As GridDataItem
        Dim OrderID As String
        Dim DateCreated As String
        item = DirectCast(e.Item, GridDataItem)
 
        If Not (e.Item.OwnerTableView Is CreditsGrid.MasterTableView) Then
 
            'Put selected values to variables
            OrderID = item("OrderID").Text
            DateCreated = item("DateCreated").Text
 
            'Removes session variables (just to be safe) & replaces with the new variables.
            Session.Remove("OrderID")
            Session.Remove("DateCreated")
            Session.Add("OrderID", OrderID)
            Session.Add("DateCreated", DateCreated)
 
            'Load Review form.
            CreditsWindow.VisibleOnPageLoad = True
 
        End If
    End If
End Sub
Tags
Grid
Asked by
TSCGlobal
Top achievements
Rank 1
Answers by
TSCGlobal
Top achievements
Rank 1
Share this question
or