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

[Solved] (using ObjectDataSource) All Edit Links point to the first record in the grid

1 Answer 81 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Emran
Top achievements
Rank 1
Emran asked on 12 Apr 2009, 07:23 PM
Hi,
I am having problems with regards to making the Edit work . All the edit Links points to the first record in the grid.
I am using  an objectdatasource as the datasource for the radgrid. I have followed the examples  in the following post:

Automatic operations with ObjectDataSource control


Please Advise, regards Emran

<telerik:RadGrid ID="MailQueueGrid" runat="server" AllowPaging="True"
        AllowSorting="True" AllowAutomaticDeletes="true"  AllowAutomaticUpdates="true"
        AutoGenerateColumns="False" AutoGenerateDeleteColumn="True"
        AutoGenerateEditColumn="True" DataSourceID="MailQueueDataSource"
        GridLines="None"  PageSize="20"  Width="800px"
        AllowFilteringByColumn="True" DataKeyNames="iQueueId" >
        <HeaderContextMenu EnableTheming="True">
            <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
        </HeaderContextMenu>
        <PagerStyle Mode="NumericPages" />

    <MasterTableView DataSourceID="MailQueueDataSource"
        AllowMultiColumnSorting="True" DataKeyNames="iQueueId"
        EditMode="PopUp" >
        <RowIndicatorColumn>
             <HeaderStyle Width="20px"></HeaderStyle>
        </RowIndicatorColumn>

        <ExpandCollapseColumn>
            <HeaderStyle Width="20px"></HeaderStyle>
        </ExpandCollapseColumn>
        
        <Columns>
            <telerik:GridBoundColumn DataField="iQueueId" HeaderText="ID"
                UniqueName="iQueueId" DataType="System.Int32" SortExpression="iQueueId"><HeaderStyle Width="5%"></HeaderStyle>
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="sMailTo" HeaderText="To"
                UniqueName="sMailTo"><HeaderStyle Width="10%"></HeaderStyle>
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="sMailBCC" HeaderText="BCC"
                UniqueName="sMailBCC"><HeaderStyle Width="10%"></HeaderStyle>
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="sMailFrom" HeaderText="From"
                UniqueName="sMailFrom"><HeaderStyle Width="10%"></HeaderStyle>
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="iFailed" HeaderText="Failed"
                UniqueName="iFailed"><HeaderStyle Width="5%"></HeaderStyle>
            </telerik:GridBoundColumn>
        </Columns>
             
        <EditFormSettings EditFormType="Template" PopUpSettings-Width="700px">
        
            <FormTemplate>
             <asp:DetailsView ID="TemplateDetailsView" DataKeyNames="iQueueId"
                runat="server" AutoGenerateRows="False"
                DataSourceID="MailQueueDataSource"
                CellPadding="4"
                GridLines="None">
                <Fields>             

                 <asp:TemplateField HeaderText="ID" SortExpression="ID">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox1" runat="server" Columns="5" Text='<%# Bind( "iQueueId" ) %>'></asp:TextBox>                 
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Bind("iQueueId") %>'></asp:Label>
                        </ItemTemplate>             
                 </asp:TemplateField>
                
                 <asp:TemplateField HeaderText="To" SortExpression="To">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox2" runat="server" Columns="50" Text='<%# Bind( "sMailTo" ) %>'></asp:TextBox>                 
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label2" runat="server" Text='<%# Bind("sMailTo") %>'></asp:Label>
                        </ItemTemplate>             
                 </asp:TemplateField>
                
                  <asp:TemplateField HeaderText="BCC" SortExpression="BCC">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox3" runat="server" Columns="50" Text='<%# Bind( "sMailBCC" ) %>'></asp:TextBox>                 
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label3" runat="server" Text='<%# Bind("sMailBCC") %>'></asp:Label>
                        </ItemTemplate>             
                 </asp:TemplateField>
                
                
                <asp:TemplateField HeaderText="From" SortExpression="From">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox4" runat="server" Columns="50" Text='<%# Bind( "sMailFrom" ) %>'></asp:TextBox>                 
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label4" runat="server" Text='<%# Bind("sMailFrom") %>'></asp:Label>
                        </ItemTemplate>             
                 </asp:TemplateField>
                
                <asp:TemplateField HeaderText="Failed" SortExpression="Failed">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox5" runat="server" Columns="5" Text='<%# Bind( "iFailed" ) %>'></asp:TextBox>                 
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label5" runat="server" Text='<%# Bind("iFailed") %>'></asp:Label>
                        </ItemTemplate>             
                 </asp:TemplateField>
                
     
                <asp:TemplateField HeaderText="Subject" SortExpression="Subject">
                        <EditItemTemplate>
                           <asp:TextBox ID="TextBox6" runat="server" TextMode="MultiLine" Rows="1" Columns="100" Text='<%# Bind( "sSubject" ) %>'></asp:TextBox>            
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label7" runat="server" Text='<%# Bind("sSubject") %>'></asp:Label>
                        </ItemTemplate>             
                 </asp:TemplateField>

                <asp:TemplateField HeaderText="Body" SortExpression="Body">
                        <EditItemTemplate>
                             <telerik:RadEditor ID="RadEditor2" runat="server" EditModes="All" Height="500"
                                    ToolsFile="~/Content/BasicTools.xml" ToolbarMode="Default"
                                    Width="100%" Content='<%# Bind("sBody") %>'>
                                    <Content></Content>
                             </telerik:RadEditor>              
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label8" runat="server" Text='<%# Bind("sBody") %>'></asp:Label>
                        </ItemTemplate>             
                 </asp:TemplateField>
                             
                <asp:CommandField ShowEditButton="True" />
                <asp:CommandField ShowInsertButton="True" />
            </Fields>
        </asp:DetailsView>                    
     </FormTemplate>

        <PopUpSettings Width="700px"></PopUpSettings>
     </EditFormSettings>
                    
    </MasterTableView>
</telerik:RadGrid>    
    
    <asp:ObjectDataSource ID="MailQueueDataSource" runat="server"   
        SelectMethod="LoadQueue" TypeName="BusinessLib.DAL.MessageAdapter"
        DeleteMethod="DeleteItemQueue"  UpdateMethod="Queue">
        <DeleteParameters>
            <asp:Parameter Name="iQueueId" Type="Int32" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="iQueueId" Type="Int32" />
            <asp:Parameter Name="sMailTo" Type="String" />
            <asp:Parameter Name="sMailBCC" Type="String" />
            <asp:Parameter Name="sMailFrom" Type="String" />
            <asp:Parameter Name="sSubject" Type="String" />
            <asp:Parameter Name="sBody" Type="String" />
            <asp:Parameter Name="iFailed" Type="Int32" />
        </UpdateParameters>
    </asp:ObjectDataSource>

1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 15 Apr 2009, 10:27 AM
Hello Emran,

The cause of this issue is that the DetailsView control in the edit template does not know what the id of the edited row is. In the currently implemented logic, the DetailsView is always bound to the whole data source and basically there is no difference between RadGrid and DetailsView. I will suggest you use this approach - FormTemplate example. If you need an independent edit form, you can use a user control to attain the functionality. Here is an example which you can use as a starting point.

Best regards,
Georgi Krustev
the Telerik team

Instantly find answers to your questions on the newTelerik Support Portal.
Check out the tipsfor optimizing your support resource searches.
Tags
Grid
Asked by
Emran
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or