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

Edit ListView/DataList like RadGrid

8 Answers 222 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ruth Dahan
Top achievements
Rank 1
Ruth Dahan asked on 14 Feb 2009, 09:49 AM
Hi,
I am using RadGrid control connected to an ObjectDataSource. I am using ItemTemplate and EditItemTemplate to show the items as in the demo of the ListView/DataList like RadGrid.
When i press the update after editing the item, the ObjectDataSource Update method is fired but the data passes is not bounded to the data in the Edit template even though it defined to be binded. i.e. all the parameters passed are nulls.

How can i edit/insert an item?

This is my code:

 <telerik:RadGrid ID="RadGrid2" runat="server" AllowAutomaticDeletes="True" AllowAutomaticInserts="True" 
        AllowAutomaticUpdates="True" DataSourceID="AgentsDatasource" GridLines="None" 
        ShowHeader="False" BorderStyle="None" GroupingEnabled="False" Skin="Outlook" 
        Width="400px"
        <HeaderContextMenu EnableTheming="True"
            <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
        </HeaderContextMenu> 
        <ItemStyle BorderStyle="None" /> 
        <MasterTableView AutoGenerateColumns="False" CommandItemDisplay="None" DataKeyNames="UserId" 
            DataSourceID="AgentsDatasource" EditMode="InPlace"  BorderStyle="None"
            <ItemTemplate > 
                <asp:Label ID="Label1" runat="server" Text='<%#Bind("SwitchId") %>'></asp:Label> 
                &nbsp; 
                <asp:Label ID="Label2" runat="server" Text='<%#Bind("Extension") %>'></asp:Label> 
                &nbsp;&nbsp; 
                <asp:LinkButton ID="btnEdit" runat="server" CommandName="Edit" Text="Edit"
                </asp:LinkButton> 
            </ItemTemplate> 
            <EditItemTemplate> 
                <asp:TextBox ID="tbSwitch" runat="server" Text='<%#Bind("SwitchId")%>'></asp:TextBox>&nbsp; 
                <asp:TextBox ID="TextBox1" runat="server" Text='<%#Bind("Extension")%>'></asp:TextBox>&nbsp;&nbsp; 
                <asp:LinkButton ID="btnEdit" runat="server" CommandName="Update" Text="Update"
                </asp:LinkButton> 
            </EditItemTemplate> 
            <RowIndicatorColumn> 
                <HeaderStyle Width="20px"></HeaderStyle> 
            </RowIndicatorColumn> 
            <ExpandCollapseColumn> 
                <HeaderStyle Width="20px"></HeaderStyle> 
            </ExpandCollapseColumn> 
            <Columns> 
                
                <telerik:GridBoundColumn DataField="SwitchId" HeaderText="SwitchId" UniqueName="SwitchId"
                </telerik:GridBoundColumn> 
                
                <telerik:GridBoundColumn DataField="Extension" HeaderText="Extension" UniqueName="Extension"
                </telerik:GridBoundColumn>                     
            </Columns> 
            <EditFormSettings> 
                <EditColumn UniqueName="EditCommandColumn1"
                </EditColumn> 
            </EditFormSettings> 
        </MasterTableView> 
        <ClientSettings> 
            <Selecting AllowRowSelect="False" EnableDragToSelectRows="True" /> 
        </ClientSettings> 
        <SelectedItemStyle BorderStyle="None" /> 
        <FilterMenu EnableTheming="True"
            <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
        </FilterMenu> 
    </telerik:RadGrid>  
    <asp:ObjectDataSource ID="AgentsDatasource" runat="server" SelectMethod="FillAgentsExtensions" 
        UpdateMethod="UpdateAgentsExtensions" TypeName="WebTester.WebTesterDataSource" 
        OldValuesParameterFormatString="original_{0}"
        <UpdateParameters> 
            <asp:Parameter Name="original_UserId" Type="Int32" /> 
            <asp:Parameter Name="SwitchId" Type="Int32" /> 
            <asp:Parameter Name="Extension" Type="String" /> 
        </UpdateParameters> 
    </asp:ObjectDataSource> 

Thanks!

Ruth.


8 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 16 Feb 2009, 06:19 AM
Hi Ruth,

Here is a codelibrary submission which demonstrates how to perform Insert/Update/Delete operation with ObjectDataSource. Give a try with that and see whether it helps.
Automatic operations with ObjectDataSource control

Thanks
Shinu



0
Ruth Dahan
Top achievements
Rank 1
answered on 16 Feb 2009, 07:16 AM

Hi Shinu,

Thanks for your reply.

I looked at the codelibrary and it seems i am doing things ok.
Moreover, when i remove the ItemTemplate and EditItemTemplate tags and use the regular approach of the grid - using the columns, the ObjectDataSource methods gets the correct values and not null as when using the ItemTemplate.

Any other advice?

Thanks!

Ruth.

0
Georgi Krustev
Telerik team
answered on 17 Feb 2009, 10:11 AM
Hello Ruth,

For your convenience I've prepared sample application which demonstrates  RadGrid with global ItemTemplate/EditItemTemplate bound via ObjectDataSource. Please find it attached to this post.

Sincerely yours,
Nikolay
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Ruth Dahan
Top achievements
Rank 1
answered on 17 Feb 2009, 05:04 PM
Hi Nikolay,
Thanks for your reply.
As i saw in your example, when you click the "Edit" button in order to edit an item, the edit form that is shown is not the one you defined on the <EditFormTemplate> tag but the automatic EditForm. the object that is passed in the 

UpdateTable(Order order) method of your ObjectDataSource is ok.

If you try to change the EditMode property of the MasterTableVie to "InPlace", the <EditFormTemplate> appearance is shown but the ObjectDataSource UpdateTable(Order order) method gets an empty "Order" object.
This demonstrate my problem accurately.

Please advice.

Thanks!
Ruth

0
Nikolay Rusev
Telerik team
answered on 20 Feb 2009, 02:15 PM
Hello Ruth,

I am afraid that RadGrid does not support InPlace editing with global EditItemTemplate.
You should use EditForms instead.

Greetings,
Nikolay
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Ruth Dahan
Top achievements
Rank 1
answered on 21 Feb 2009, 10:13 AM
Thanks Nikolay,
When i use "EditForms" istead of "InPlace" edit mode, the EditItemTamplate defined is not shown but the automatic edit form with is automatic format.
How can i display the global EditItemTamplate i defined when the user is in edit mode?

Thanks,
Ruth
0
Accepted
Georgi Krustev
Telerik team
answered on 24 Feb 2009, 11:55 AM
Hi Ruth,

To attain the functionality you are searching for you have two options.
The first one is to use InPlace edit mode. Thus the global EditItemTemplate will be applied. The problem here is that the Update method will not get the correct data, entered from edit form. To work around this issue you can set all parameters you want to pass to the method and to assign them to the ObjectDataSource when the update action is performed.

Here is a code snippet showing how to achieve this:
    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectCountMethod="SelectCount" 
        SelectMethod="Select" TypeName="GuidTestCollection"  
         UpdateMethod="UpdateTable"
         <UpdateParameters> 
            <asp:Parameter Name="OrderID" Type="Int32" /> 
            <asp:Parameter Name="CustomerID" Type="String" /> 
         </UpdateParameters> 
    </asp:ObjectDataSource> 
    protected void RadGrid2_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) 
    { 
        if (e.CommandName == RadGrid.UpdateCommandName)  
        { 
            string OrderID = ((System.Web.UI.WebControls.TextBox)(e.Item.FindControl("txtOrderId"))).Text; 
            string CustomerID = ((System.Web.UI.WebControls.TextBox)(e.Item.FindControl("TextBox3"))).Text; 
 
            ObjectDataSource1.UpdateParameters["OrderID"].DefaultValue = OrderID; 
            ObjectDataSource1.UpdateParameters["CustomerID"].DefaultValue = CustomerID; 
        } 
    } 
Custom class:
    public void UpdateTable(int OrderID, string CustomerID) 
    { 
        //TODO: Implement the update of the edited row, passed as parameter 
    } 


The other option is to use a custom user control, which has to implement IBindableTemplate interface. Thus you can set EditForms edit mode. Here you can find some more info on this matter (Edit section).

For your convenience I have attached the modified test project.

Give it a try and let me know how it goes.

Regards,
Georgi Krustev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Ruth Dahan
Top achievements
Rank 1
answered on 01 Mar 2009, 07:08 AM
Thanks Georgi!
i used your first solution and it is working :-)
Tags
Grid
Asked by
Ruth Dahan
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Ruth Dahan
Top achievements
Rank 1
Georgi Krustev
Telerik team
Nikolay Rusev
Telerik team
Share this question
or