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

radgrid updateCommand reload into session variable

1 Answer 115 Views
Grid
This is a migrated thread and some comments may be shown as answers.
AName
Top achievements
Rank 1
AName asked on 20 Jan 2014, 08:35 PM

Hi there,


I am attempting to refresh a datatable with the latest updates from a radgrid.



Steps

1. Two Rows exist

2. User Clicks "edit"

3. Two columns become editable

4. User edits 1 or both values clicks "update"

5. Within myGrid_UpdateCommand session variable gets updated.

6. Currently only returns newly edited row, ignores row not edited.

7. WANTED: to always return all the rows, edited and unchanged.



Code

 


Protected Sub rgTaxRate_UpdateCommand(ByVal sender As Object, ByVal e As GridCommandEventArgs) Handles rgTaxRate.UpdateCommand
Dim newDataTable As DataTable = New DataTable
 
 ' build column names
For Each col As GridColumn In rgTaxRate.Columns
    Dim dCol As DataColumn = New DataColumn(col.UniqueName)
    newDataTable.Columns.Add(dCol)
Next
 
; attempt to create row
For Each row As GridDataItem In rgTaxRate.Items
    Dim dr As DataRow = newDataTable.NewRow
    For Each col As GridColumn In rgTaxRate.Columns
        dr(col.UniqueName) = row(col.UniqueName).Text
    Next
    newDataTable.Rows.Add(dr)
Next
 
Session("MyTempTable") = newDataTable


this is based on another thread I saw but I am unsure for the life of me how they got it to work.

Here is my aspx code

<telerik:RadGrid OnItemEvent="rgTaxRate_ItemEvent" ID="rgTaxRate" Width="100%" AllowPaging="True" PageSize="8" runat="server" AllowSorting="True" GridLines="None"
                                        AutoGenerateColumns="True" ShowStatusBar="True" CellSpacing="0" EnableViewState="false" AutoGenerateEditColumn="true" OnUpdateCommand="rgTaxRate_UpdateCommand">
                                        <PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>
                                        <MasterTableView ShowFooter="false" DataKeyNames="TaxID" EditMode="InPlace" Width="100%" CommandItemDisplay="Bottom"  HorizontalAlign="NotSet" AutoGenerateColumns="false">
                                        <CommandItemTemplate>
                                            <div style="padding: 5px 5px; text-align:left;">
                                                <asp:LinkButton ID="reloadTaxes" Text="Reset to Defaults" CommandName="Reload" runat="server" OnCommand="lbReload_Command"></asp:LinkButton>
                                            </div>
                                        </CommandItemTemplate>
                                        <Columns>
                                            <telerik:GridBoundColumn DataField="TaxID" HeaderText="TaxID" UniqueName="TaxID" SortExpression="TaxID" Display="false"></telerik:GridBoundColumn>
                                            <telerik:GridTemplateColumn DataField="TaxDescription" UniqueName="TaxDescription" HeaderText="Tax Description" SortExpression="TaxDescription" HeaderStyle-Width="128px" ItemStyle-Width="128px" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Left">
                                                <ItemTemplate>
                                                    <%#DataBinder.Eval(Container.DataItem, "TaxDescription")%>
                                                </ItemTemplate>
                                                <EditItemTemplate>
                                                    <telerik:RadTextBox Width="128px" runat="server" ID="rgTaxRate_Description" MaxLength="20" Text='<%#Eval("TaxDescription") %>'></telerik:RadTextBox>
                                                </EditItemTemplate>
                                            </telerik:GridTemplateColumn>
                                            <telerik:GridTemplateColumn DataField="TaxRate" UniqueName="TaxRate" HeaderText="Tax Rate" SortExpression="TaxRate"  ItemStyle-Width="56px"  HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Left">
                                                <ItemTemplate>
                                                    <%#DataBinder.Eval(Container.DataItem, "TaxRate")%>
                                                </ItemTemplate>
                                                <EditItemTemplate>
                                                    <telerik:RadNumericTextBox Width="56px" ID="rgTaxRate_Amount" Type="Percent" MinValue="0" MaxValue="100" MaxLength="3" NumberFormat-DecimalDigits="0" NumberFormat-GroupSeparator="," Culture="en-US"  runat="server" DbValue='<%#Eval("TaxRate") %>'>
                                                    </telerik:RadNumericTextBox>
                                                </EditItemTemplate>
                                            </telerik:GridTemplateColumn>
                                        </Columns>
                                        </MasterTableView>
                                        <ClientSettings></ClientSettings>
                                        <FilterMenu EnableTheming="True">
                                            <CollapseAnimation Duration="200" Type="OutQuint"></CollapseAnimation>
                                        </FilterMenu>
                                    </telerik:RadGrid>
                                    <telerik:GridTextBoxColumnEditor runat="server" ID="rgTaxRate_Amount">  
                                        <TextBoxStyle Width="50px" />
                                    </telerik:GridTextBoxColumnEditor>








1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 21 Jan 2014, 05:59 AM
Hi ,

I guess you want to access all the rows in the UpdateCommand event. Since you have TemplateColumn it may not be available when using "Column.UniqueName" since they are accessed using the controls that they use. You can add the Column to the DataKeyNames and try the following code snippet:

ASPX:
<MasterTableView DataKeyNames="TaxID,TaxDescription,TaxRate" . . >

VB:
Protected Sub rgTaxRate_UpdateCommand(sender As Object, e As GridCommandEventArgs)
    Dim dt As New DataTable()
    Dim columncount As Integer = 0
    For Each column As GridColumn In rgTaxRate.MasterTableView.Columns
        If Not String.IsNullOrEmpty(column.UniqueName) AndAlso Not String.IsNullOrEmpty(column.HeaderText) Then
            columncount += 1
            dt.Columns.Add(column.UniqueName, GetType(String))
        End If
    Next
    Dim dr As DataRow
    For Each item As GridDataItem In rgTaxRate.MasterTableView.Items
        dr = dt.NewRow()
 
        For i As Integer = 0 To columncount - 1
            dr(i) = item.GetDataKeyValue(rgTaxRate.MasterTableView.Columns(i).UniqueName).ToString()
        Next
        dt.Rows.Add(dr)
    Next
End Sub

Thanks,
Princy
Tags
Grid
Asked by
AName
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or