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

Issues with GridDataInsertItem.ExtractValues

3 Answers 56 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nishant
Top achievements
Rank 1
Nishant asked on 18 Jul 2012, 06:50 PM
Hi,

I'm trying to insert/update values in an XML file using XMLDataSource and RadGrid. Below is my code :

aspx
<telerik:RadGrid ID="RadGrid1" runat="server" CellSpacing="0" DataSourceID="XmlDataSource1"
        GridLines="None">
        <MasterTableView AutoGenerateColumns="False" DataSourceID="XmlDataSource1" EditMode="InPlace"
            CommandItemDisplay="Bottom" InsertItemDisplay="Bottom">
            <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
            <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
            </RowIndicatorColumn>
            <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
            </ExpandCollapseColumn>
            <Columns>
                <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
                    <ItemStyle CssClass="MyImageButton" />
                </telerik:GridEditCommandColumn>
                <telerik:GridBoundColumn DataField="ruleset_id" FilterControlAltText="Filter ruleset_id column"
                    HeaderText="ruleset_id" SortExpression="ruleset_id" UniqueName="ruleset_id">
                </telerik:GridBoundColumn>
                <telerik:GridTemplateColumn DataField="list_code" FilterControlAltText="Filter list_code column"
                    HeaderText="list_code" SortExpression="list_code" UniqueName="list_code">
                    <EditItemTemplate>
                        <telerik:RadComboBox ID="ListCodeComboBox" runat="server" SelectedValue='<%# Bind("list_code") %>'>
                            <Items>
                                <telerik:RadComboBoxItem Text="BA001" Value="BA001" />
                                <telerik:RadComboBoxItem Text="BA002" Value="BA002" />
                                <telerik:RadComboBoxItem Text="BA003" Value="BA003" />
                            </Items>
                        </telerik:RadComboBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="list_codeLabel" runat="server" Text='<%# Eval("list_code") %>'></asp:Label>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridBoundColumn DataField="seq_no" FilterControlAltText="Filter seq_no column"
                    HeaderText="seq_no" SortExpression="seq_no" UniqueName="seq_no">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="new_field_name" FilterControlAltText="Filter new_field_name column"
                    HeaderText="new_field_name" SortExpression="new_field_name" UniqueName="new_field_name">
                </telerik:GridBoundColumn>
                <telerik:GridTemplateColumn DataField="field_name" FilterControlAltText="Filter field_name column"
                    HeaderText="Field Name" SortExpression="field_name" UniqueName="field_name">
                    <EditItemTemplate>
                        <telerik:RadComboBox ID="FieldNameComboBox" runat="server" DataSourceID="XmlDataSource2"
                            DataTextField="field_name" DataValueField="field_length" AppendDataBoundItems="True">
                            <Items>
                                <telerik:RadComboBoxItem Text="Select" Value="" />
                            </Items>
                        </telerik:RadComboBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="field_nameLabel" runat="server" Text='<%# Eval("field_name") %>'></asp:Label>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridBoundColumn DataField="concat_constant_value" FilterControlAltText="Filter concat_constant_value column"
                    HeaderText="concat_constant_value" SortExpression="concat_constant_value" UniqueName="concat_constant_value">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="concat_substring_start_pos" FilterControlAltText="Filter concat_substring_start_pos column"
                    HeaderText="concat_substring_start_pos" SortExpression="concat_substring_start_pos"
                    UniqueName="concat_substring_start_pos">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="concat_substring_end_pos" FilterControlAltText="Filter concat_substring_end_pos column"
                    HeaderText="concat_substring_end_pos" SortExpression="concat_substring_end_pos"
                    UniqueName="concat_substring_end_pos">
                </telerik:GridBoundColumn>
            </Columns>
            <EditFormSettings>
                <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                </EditColumn>
            </EditFormSettings>
        </MasterTableView>
    </telerik:RadGrid>
    <asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="C:\TEMP\CONCATENATION_DETAIL_TEMP.XML">
    </asp:XmlDataSource>
    <asp:XmlDataSource ID="XmlDataSource2" runat="server" DataFile="C:\TEMP\LAYOUT_FIELDS_TABLE.XML"
        TransformFile="C:\TEMP\LAYOUT_FIELDS_TABLE.XSL"></asp:XmlDataSource>

aspx.vb
Private Sub RadGrid1_InsertCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.InsertCommand
    Dim ht As Hashtable = New Hashtable()
    DirectCast(e.Item, GridDataInsertItem).ExtractValues(ht)
    Dim s As String = ""
    For Each entry In ht
        s = s + "Field Name : " + entry.Key.ToString() + " , Value : " + entry.Value + vbCrLf
    Next
    MsgBox(s)
End Sub

output:
Field Name : concat_substring_start_pos , Value : 7
Field Name : concat_constant_value , Value : 6
Field Name : seq_no , Value : 3
Field Name : list_code , Value : BA002
Field Name : ruleset_id , Value : 1
Field Name : concat_substring_end_pos , Value : 8
Field Name : new_field_name , Value : 4  


I'm encountering 2 issues :
1. Column 5 (field_name), which is a template column that uses RadComboBox for editing and is bound to another data source for fetching values, is not extracted into the Hashtable.
2. Values in the hashtable are not in ordered in the sequence of RadGrid columns.

Please suggest the solutions for these (Issue 1 is higher priority)

Thanks,
Nishant

3 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 23 Jul 2012, 03:10 PM
Hello Nishant,

Since the Hashtable does not have a sorted structure, but keeps the inserted values by their generated hash code, it is not possible to extract them directly in their original order. However, you could use the following approach to do that:
Protected Sub RadGrid1_ItemCommand(sender As Object, e As GridCommandEventArgs) Handles RadGrid1.ItemCommand
    If e.CommandName = RadGrid.UpdateCommandName Then
        Dim newValues As New Hashtable()
        TryCast(e.Item, GridEditableItem).ExtractValues(newValues)
 
        For Each column As GridColumn In RadGrid1.MasterTableView.RenderColumns
            If newValues.ContainsKey(column.UniqueName) Then
                Dim value As String = DirectCast(newValues(column.UniqueName), String)
            End If
        Next
    End If
End Sub

On my side the following ComboBox successfully gets extracted by the RadGrid:

<telerik:RadComboBox ID="ListCodeComboBox" runat="server" SelectedValue='<%# Bind("ShipName") %>'
         >
         <Items>
             <telerik:RadComboBoxItem Text="BA001" Value="Rancho grande" />
             <telerik:RadComboBoxItem Text="BA002" Value="Cactus Comidas para llevar" />
             <telerik:RadComboBoxItem Text="BA003" Value="Ernst Handel" />
         </Items>
     </telerik:RadComboBox>

Please ensure that the unique name of the column is correctly assigned.

All the best,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Nishant
Top achievements
Rank 1
answered on 23 Jul 2012, 03:34 PM
Hi Eyup,

The ListCodeComboBox value had no problem, the problem was with FieldNameComboBox as stated in my original post (Issue 1).
Please help me resolve that.

Thanks,
Nishant
0
Accepted
Eyup
Telerik team
answered on 26 Jul 2012, 12:30 PM
Hi Nishant,

Please note that you have to use SelectedValue='<%# Bind("YourField") %>' in order for RadGrid to extract successfully the value from the combo box.

An alternative approach would be to access the RadComboBox and get its value manually:
Dim combo As RadComboBox = TryCast(e.Item.FindControl("FieldNameComboBox "), RadComboBox)
Dim comboText As String = combo.Text
Dim comboValue As String = combo.SelectedValue

I hope this will prove helpful.

Regards,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Nishant
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Nishant
Top achievements
Rank 1
Share this question
or