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

Getting the changed data from update

2 Answers 56 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ben
Top achievements
Rank 1
Ben asked on 22 Jun 2010, 04:05 PM
Hello!

I currently have a RadGrid bound to a List containing a custom class. This list gets populated when a user drags a node from a TreeView.

I'd like to let the user select a value from the dropdown and enter their own value inside the "Value" field and then save this to the List.
I've tried doing this using the automatic edit column but inside the "RadGrid_UpdateCommand" I can't seem to find the new data! I'm probably missing something pretty simple. :)

Here's the code:

<telerik:RadGrid ID="conditionsGrid" runat="server" Width="252px"  
                Height="116px" GridLines="None" AllowMultiRowSelection="True"  
                onneeddatasource="conditionsGrid_NeedDataSource" Skin="Sunset" CssClass="addedTablesGrid"  
                    AutoGenerateEditColumn="True" onitemupdated="conditionsGrid_ItemUpdated"  
                    onupdatecommand="conditionsGrid_UpdateCommand"  
                    AllowAutomaticUpdates="true" onitemcommand="conditionsGrid_ItemCommand"
                <MasterTableView Width="100%"
                    <NoRecordsTemplate> 
                        Drag columns here. 
                    </NoRecordsTemplate> 
                    <Columns> 
                        <telerik:GridBoundColumn HeaderText="Column" UniqueName="columnColumn" DataField="columnName" DataType="System.String" EmptyDataText="Ooops" ReadOnly="true"
                        </telerik:GridBoundColumn> 
                        <telerik:GridTemplateColumn HeaderText="Value" UniqueName="type1"
                            <ItemTemplate> 
                                <asp:DropDownList runat="server"
                                    <asp:ListItem Text="Equals" Value="="></asp:ListItem> 
                                    <asp:ListItem Text="Greater than" Value=">"></asp:ListItem> 
                                    <asp:ListItem Text="Less than" Value="<"></asp:ListItem> 
                                    <asp:ListItem Text="Not equal to" Value="!="></asp:ListItem> 
                                </asp:DropDownList> 
                            </ItemTemplate> 
                        </telerik:GridTemplateColumn> 
                        <telerik:GridBoundColumn HeaderText="Value" UniqueName="valueColumn" DataField="value" > 
                        </telerik:GridBoundColumn> 
                    </Columns> 
                </MasterTableView> 
                <ClientSettings AllowRowsDragDrop="true"
                    <Selecting AllowRowSelect="true" EnableDragToSelectRows="true" /> 
                </ClientSettings> 
            </telerik:RadGrid> 



        protected void ColumnTreeView_NodeDrop(object sender, RadTreeNodeDragDropEventArgs e) 
        { 
            if (string.IsNullOrEmpty(e.HtmlElementID)) 
                return
 
            if (e.HtmlElementID == "MainBodyPlaceHolder_conditionsGrid"
            { 
                List<GridConditionRow> added = AddedTableConditions; 
 
                foreach (RadTreeNode node in e.DraggedNodes) 
                { 
                    GridConditionRow Row = new GridConditionRow(); 
                    Row.columnName = node.Value; 
                    Row.value = ""
                    added.Add(Row);                     
                } 
                 
                AddedTableConditions = added; 
 
                conditionsGrid.DataSource = AddedTableConditions; 
                conditionsGrid.DataBind(); 
            } 
        } 
 
        protected void conditionsGrid_UpdateCommand(object source, GridCommandEventArgs e) 
        { 
            //It's here that I can't seem to find the updated information to alter the List with. 
        } 


Thanks! 
Ben.

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 23 Jun 2010, 11:57 AM
 Hello Ben,

If you want to render the control in edit mode as well, then you need to place the control in EditItemTemplate of GridTemplateColumn. And in order to get the SelectedValue in UpdateCommand, access the control and then get the value. Here is an example.

ASPX:
<telerik:GridBoundColumn HeaderText="Column" UniqueName="Column" DataField="FirstName" 
    DataType="System.String" EmptyDataText="Ooops" ReadOnly="true"
</telerik:GridBoundColumn> 
<telerik:GridTemplateColumn HeaderText="Value" UniqueName="type1"
    <ItemTemplate> 
        <asp:DropDownList ID="DropDownList1" runat="server"
            <asp:ListItem Text="Equals" Value="="></asp:ListItem> 
            <asp:ListItem Text="Greater than" Value=">"></asp:ListItem> 
            <asp:ListItem Text="Less than" Value="<"></asp:ListItem> 
            <asp:ListItem Text="Not equal to" Value="!="></asp:ListItem> 
        </asp:DropDownList> 
    </ItemTemplate> 
    <EditItemTemplate> 
        <asp:DropDownList ID="DropDownList1" runat="server"
            <asp:ListItem Text="Equals" Value="="></asp:ListItem> 
            <asp:ListItem Text="Greater than" Value=">"></asp:ListItem> 
            <asp:ListItem Text="Less than" Value="<"></asp:ListItem> 
            <asp:ListItem Text="Not equal to" Value="!="></asp:ListItem> 
        </asp:DropDownList> 
    </EditItemTemplate> 
</telerik:GridTemplateColumn> 
<telerik:GridBoundColumn HeaderText="Value" UniqueName="valueColumn" DataField="value"
</telerik:GridBoundColumn> 

C#:
 
 protected void conditionsGrid_UpdateCommand(object source, GridCommandEventArgs e) 
 { 
    GridEditFormItem edititem = (GridEditFormItem)e.Item; 
    DropDownList drlist = (DropDownList)edititem.FindControl("DropDownList1"); 
    string dropListValue = drlist.SelectedValue; 
    TextBox txt = (TextBox)edititem["valueColumn"].Controls[0]; 
    string txtValue = txt.Text; 
    
 } 




Thanks,
Princy.
0
Ben
Top achievements
Rank 1
answered on 25 Jun 2010, 01:33 PM
Thanks!

This helped sort out my problem :)
Tags
Grid
Asked by
Ben
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Ben
Top achievements
Rank 1
Share this question
or