RadContextMenu database update

1 posts, 0 answers
  1. Nimesh
    Nimesh avatar
    24 posts
    Member since:
    Dec 2007

    Posted 29 May 2012 Link to this post

    I have a radcontextmenu with a radgrid. I attach navigate urls with Querystring values from the Radgrid's datakey values client side. I want to add an additional menuitem that performs a simple database action of update based on the datakey value in the radgrid. I cant find a way of doing this after searching pretty hard, so I need help. Perhaps all I need to do is somehow trigger a server side function, or maybe there is another way. The radgrid uses SQL datasource declarative binding. I would like to do the database update for all the rows selected in the RadGrid based on the datakeynames of each row. So basically, I would like add a menu item that asks "Update Selected Rows?" in an alert, then perform the update for each selected row.

    <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" Width="256px" Height="64px" runat="server">
                <asp:Label ID="Label2" runat="server" ForeColor="Red">Loading... </asp:Label>
            </telerik:RadAjaxLoadingPanel>
      
            <telerik:RadCodeBlock runat="server" ID="radCodeBlock">
                <script type="text/javascript">
                    function showFilterItem() {
                        $find('<%=RadGrid1.ClientID %>').get_masterTableView().showFilterItem();
                    }
                    function hideFilterItem() {
                        $find('<%=RadGrid1.ClientID %>').get_masterTableView().hideFilterItem();
                    }
                    function RowContextMenu(sender, eventArgs) {
                        var NavigateUrl;
                        var grid = window["<%= RadGrid1.ClientID %>"];
                        var masterTableView = grid.MasterTableView;
                        var menu = $find("<%=RadContextMenu1.ClientID %>");
                        //document.getElementById("<%= Label1.ClientID %>").innerHTML = eventArgs.getDataKeyValue("ReservationID");
                        NavigateUrl = document.getElementById("<%= Label1.ClientID %>").innerHTML = eventArgs.getDataKeyValue("ReservationID");
                        var evt = eventArgs.get_domEvent();
                        var menuEditItem = menu.findItemByText("Edit");
                        menuEditItem.set_navigateUrl("Reservation.aspx?ReservationID=" + NavigateUrl);
                        menu.show(evt);
                    }
                    function PopulateParticipant(sender, eventArgs) {
                        var ResID;
                        ResID = eventArgs.getDataKeyValue("ReservationID");
                    }
                    function OnDateSelected(sender, eventArgs) {
                        sender.set_autoPostBack(true);
                    
      
                </script>
            </telerik:RadCodeBlock>
      
      
        <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
        <telerik:RadGrid ID="RadGrid1" runat="server" PageSize="500" Height="600px" AllowFilteringByColumn="True" 
            AllowPaging="True" AllowMultiRowSelection="true" AllowSorting="True" DataSourceID="SqlDsGetRetReservations"
            GridLines="None" ShowGroupPanel="True" Skin="Windows7" 
            AutoGenerateColumns="False" EnableLinqExpressions="false">
            <PagerStyle Mode="Slider"></PagerStyle>
            <ClientSettings AllowColumnsReorder="True" AllowDragToGroup="True" 
                ReorderColumnsOnClient="True">
                <ClientEvents OnRowContextMenu="RowContextMenu" OnRowSelected="PopulateParticipant" />
                <Scrolling AllowScroll="True" UseStaticHeaders="True" />
                <Selecting AllowRowSelect="true" />
            </ClientSettings>
            <MasterTableView DataSourceID="SqlDsGetRetReservations" NoMasterRecordsText="No Reservations created during this period." PagerStyle-Mode="Advanced" DataKeyNames="ReservationID" ClientDataKeyNames="ReservationID"  AllowFilteringByColumn="true">
                <Columns>
                <telerik:GridButtonColumn ButtonType="LinkButton" CommandName="CancelRes" HeaderText="Cancel" UniqueName="Cancel" Text="Cancel" ItemStyle-Width="35px"></telerik:GridButtonColumn>
      
                    <telerik:GridBoundColumn DataField="ReservationID" FilterControlWidth="50px" ItemStyle-Width="100px" HeaderText="Res ID" SortExpression="ReservationID" UniqueName="ResID">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="DeptID" FilterControlWidth="50px" ItemStyle-Width="100px" HeaderText="DeptID" SortExpression="DeptID" UniqueName="DeptID">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Chairperson" HeaderText="Chairperson" ItemStyle-Width="150px"  AutoPostBackOnFilter="false" SortExpression="Chairperson" UniqueName="Chairperson">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Passcode" FilterControlWidth="50px" ItemStyle-Width="100px" HeaderText="Passcode" SortExpression="Passcode" UniqueName="Passcode">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="PasscodeM" FilterControlWidth="50px" ItemStyle-Width="100px" HeaderText="PasscodeM" SortExpression="PasscodeM" UniqueName="PasscodeM">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="ContactName" HeaderText="ContactName" ItemStyle-Width="150px"  SortExpression="ContactName" UniqueName="ContactName">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="StatusID" HeaderText="Status" SortExpression="Status" UniqueName="Status">
                    </telerik:GridBoundColumn
                </Columns>
                        </MasterTableView>
        </telerik:RadGrid>
        <telerik:RadContextMenu ID="RadContextMenu1" runat="server" OnItemClick="RadContextMenu1_ItemClick" Skin="Windows7">
            <Targets>
                <telerik:ContextMenuControlTarget ControlID="RadGrid1" />
            </Targets>
            <Items>
                <telerik:RadMenuItem Text="Add" />
                <telerik:RadMenuItem Text="Edit" />
            </Items>
        </telerik:RadContextMenu>

     Any help would be appreciated.

Back to Top