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

[Solved] Multi row update or delete on RadGrid

1 Answer 429 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Patrick
Top achievements
Rank 1
Patrick asked on 04 Feb 2008, 09:33 AM
I have been working on this problem all night. I can't seem to figure out what the problem is. I am trying to do a grid control just like the one you have an example for at:

http://www.telerik.com/DEMOS/ASPNET/Prometheus/Grid/Examples/Programming/WebGrid/DefaultCS.aspx

The only difference is that I am using a SqlDataSource instead of the sds:SessionDataSource that is used in the example. Also, my data is a bit different with 2 dates that need to be selected. This should not matter though. I can edit, add, and delete a single row at a time with the links on the right of the grid. If I try to edit or delete using the checkboxes and the links at the top of the control, it does not work. It just does a page refresh and its back to a cleared control.

Here is the code:



<asp:Content ID="Content1" ContentPlaceHolderID="_mainContent" Runat="Server"
<asp:ScriptManager ID="ScriptManager1" runat="server" /> 
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"
            <AjaxSettings> 
                <telerik:AjaxSetting AjaxControlID="RadGrid1"
                    <UpdatedControls> 
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1"/> 
                    </UpdatedControls> 
                </telerik:AjaxSetting> 
            </AjaxSettings> 
        </telerik:RadAjaxManager> 
        
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Height="75px" Width="75px" Transparency="50"
            <img alt="Loading..." src='<%= RadAjaxLoadingPanel.GetWebResourceUrl(Page, "Telerik.Web.UI.Skins.Default.Ajax.loading.gif") %>' style="border:0;" /> 
        </telerik:RadAjaxLoadingPanel> 
            
        <telerik:RadGrid ID="RadGrid1" AllowMultiRowSelection="true" AllowMultiRowEdit="true" AllowSorting="true" 
            Skin="WebBlue" runat="server" AllowAutomaticDeletes="True" AllowAutomaticInserts="True" 
            Width="97%" PageSize="14" AllowAutomaticUpdates="True" AllowPaging="True" AutoGenerateColumns="False" 
            DataSourceID="mySqlDataSourceGrid" ShowStatusBar="true" AutoGenerateEditColumn="true" AutoGenerateDeleteColumn="true"
            <PagerStyle Mode="Slider" /> 
            <ClientSettings> 
                <Selecting AllowRowSelect="true" /> 
            </ClientSettings> 
            <MasterTableView CommandItemDisplay="Top" DataKeyNames="eventid" DataSourceID="mySqlDataSourceGrid" 
                EditMode="EditForms" AutoGenerateColumns="False" Width="100%"
                <CommandItemTemplate> 
                    <div style="padding:10px 0px;">&nbsp;&nbsp; 
                    <asp:LinkButton Style="vertical-align: bottom" ID="btnEditSelected" runat="server" CommandName="EditSelected" CausesValidation="false" Visible='<%# RadGrid1.EditIndexes.Count == 0 %>'><img style="border:0px;vertical-align:middle;" alt="" src="images/Edit.gif" /> Edit Selected Events</asp:LinkButton> 
                    <asp:LinkButton ID="btnUpdateEdited" runat="server" CommandName="UpdateEdited" Visible='<%# RadGrid1.EditIndexes.Count > 0 %>'><img style="border:0px;vertical-align:middle;" alt="" src="images/Update.gif" /> Update Events</asp:LinkButton> 
                    &nbsp; 
                    <asp:LinkButton ID="btnCancel" runat="server" CommandName="CancelAll" CausesValidation="false" Visible='<%# RadGrid1.EditIndexes.Count > 0 || RadGrid1.MasterTableView.IsItemInserted %>'><img style="border:0px;vertical-align:middle;" alt="" src="images/Cancel.gif" /> Cancel editing</asp:LinkButton> 
                    &nbsp; 
                    <asp:LinkButton ID="LinkButton2" runat="server" CommandName="InitInsert" Visible='<%# !RadGrid1.MasterTableView.IsItemInserted %>'><img style="border:0px;vertical-align:middle;" alt="" src="images/AddRecord.gif" /> Add new Event</asp:LinkButton> 
                    <asp:LinkButton ID="LinkButton3" runat="server" CommandName="PerformInsert" Visible='<%# RadGrid1.MasterTableView.IsItemInserted %>'><img style="border:0px;vertical-align:middle;" alt="" src="images/Insert.gif" /> Add this Event</asp:LinkButton> 
                    &nbsp; 
<asp:LinkButton ID="LinkButton1" OnClientClick="javascript:return confirm('Delete all selected Events?')" 
runat="server" CommandName="DeleteSelected" CausesValidation="false"><img style="border:0px;vertical-align:middle;" alt="" src="images/Delete.gif" /> Delete Selected Events</asp:LinkButton> 
                    &nbsp;&nbsp;&nbsp; 
                    <asp:LinkButton ID="LinkButton4" runat="server" CommandName="RebindGrid"><img style="border:0px;vertical-align:middle;" alt="" src="images/Refresh.gif" /> Refresh Event list</asp:LinkButton> 
                    </div> 
                </CommandItemTemplate> 
                <Columns> 
                    <telerik:GridClientSelectColumn HeaderStyle-Width="40px" /> 
                    <telerik:GridBoundColumn DataField="eventid" HeaderText="ID" ReadOnly="True" SortExpression="EventID" 
                        UniqueName="EventID" Visible="false"
                        <HeaderStyle Width="20px" ForeColor="Silver" /> 
                        <ItemStyle ForeColor="Silver" /> 
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="eventname" HeaderText="Event Name" SortExpression="eventname" 
                        UniqueName="eventname"
                    </telerik:GridBoundColumn> 
                    
                    <telerik:GridDateTimeColumn DataField="eventstart" HeaderText="Event Start Date" SortExpression="eventstart" UniqueName="eventstart" EditFormColumnIndex="1"
                    </telerik:GridDateTimeColumn> 
 
                    <telerik:GridDateTimeColumn DataField="eventend" HeaderText="Event End Date" SortExpression="eventend" UniqueName="eventend" EditFormColumnIndex="1"
                    </telerik:GridDateTimeColumn> 
                    
                    <telerik:GridBoundColumn DataField="eventlocation" HeaderText="Event Location" SortExpression="eventlocation" 
                        UniqueName="eventlocation"
                    </telerik:GridBoundColumn> 
                    
                    <telerik:GridBoundColumn DataField="eventurl" HeaderText="Event URL" SortExpression="eventurl" 
                        UniqueName="eventurl"
                    </telerik:GridBoundColumn> 
                </Columns> 
                
                <EditFormSettings ColumnNumber="2" CaptionDataField="EventName" CaptionFormatString="Edit properties of Event {0}"
                    <FormTableItemStyle Wrap="False"></FormTableItemStyle> 
                    <FormCaptionStyle CssClass="EditFormHeader"></FormCaptionStyle> 
                    <FormMainTableStyle GridLines="Horizontal" CellSpacing="0" CellPadding="3" BackColor="White" 
                        Width="100%" /> 
                    <FormTableStyle CellSpacing="0" CellPadding="2" CssClass="module" Height="110px" 
                        BackColor="White" /> 
                    <FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle> 
                    <EditColumn ButtonType="ImageButton" 
                        UpdateImageUrl="images\Update.gif" EditImageUrl="images\Edit.gif" 
                        InsertImageUrl="images\Insert.gif" CancelImageUrl="images\Cancel.gif" 
                        InsertText="Insert Order" UpdateText="Update record" UniqueName="EditCommandColumn1" CancelText="Cancel edit"
                    </EditColumn> 
                    <FormTableButtonRowStyle HorizontalAlign="Right" CssClass="EditFormButtonRow"></FormTableButtonRowStyle> 
                </EditFormSettings> 
            </MasterTableView> 
        </telerik:RadGrid><br /> 
                
                <asp:SqlDataSource ID="mySqlDataSourceGrid" runat="server" 
                    datasourcemode="DataSet" 
                    ConnectionString="<%$ ConnectionStrings:xConnectionString %>" 
                    SelectCommand="SELECT * FROM [eventtb]" 
                    DeleteCommand="DELETE FROM [eventtb] WHERE [eventid] = @eventid" 
                    updatecommand="UPDATE [eventtb] SET [eventname] = @eventname, [eventstart] = @eventstart, [eventend] = @eventend, [eventlocation] = @eventlocation, [eventurl] = @eventurl WHERE eventid = @eventid" 
                    insertcommand="INSERT INTO [eventtb] (eventname, eventstart, eventend, eventlocation, eventurl) VALUES (@eventname, @eventstart, @eventend, @eventlocation, @eventurl)" 
                    FilterExpression="[eventid] = {0}"
                    <filterparameters> 
                        <asp:ControlParameter Name="eventid" ControlId="RadGrid1" PropertyName="SelectedValue" Type="String" /> 
                    </filterparameters> 
                    <DeleteParameters> 
                        <asp:Parameter Type="Int32" Name="eventid" /> 
                    </DeleteParameters> 
                    <UpdateParameters> 
                        <asp:Parameter Type="Int32" Name="eventid" /> 
                        <asp:Parameter Type="String" Name="eventname" /> 
                        <asp:Parameter Type="DateTime" Name="eventstart" /> 
                        <asp:Parameter Type="DateTime" Name="eventend" /> 
                        <asp:Parameter Type="String" Name="eventlocation" /> 
                        <asp:Parameter Type="String" Name="eventurl" /> 
                    </UpdateParameters> 
                    <InsertParameters> 
                        <asp:Parameter Type="Int32" Name="eventid" /> 
                        <asp:Parameter Type="String" Name="eventname" /> 
                        <asp:Parameter Type="DateTime" Name="eventstart" /> 
                        <asp:Parameter Type="DateTime" Name="eventend" /> 
                        <asp:Parameter Type="String" Name="eventlocation" /> 
                        <asp:Parameter Type="String" Name="eventurl" /> 
                    </InsertParameters> 
                </asp:SqlDataSource> 
 
 
</asp:Content> 



Any help with this would be great.

Thanks,
Patrick

1 Answer, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 05 Feb 2008, 09:09 AM
Hi Patrick,

Please review the following code library elaborating on automatic operations with SQLDataSource control and let us know if still having problems.

Kind regards,
Steve
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
Patrick
Top achievements
Rank 1
Answers by
Steve
Telerik team
Share this question
or