Delete row from RadGrid whitout using ObjectDataSource

3 posts, 0 answers
  1. Jiten
    Jiten avatar
    67 posts
    Member since:
    Dec 2010

    Posted 02 Feb 2011 Link to this post

    Hello Sir/Madam,
    How to delete row from RadGrid  using C# code.
    I dont want to used ObjectDataSource because i want to manage in code using 5 or more delete or update sql query according to time and condition. This can more flexible. I see delete row using ObjectDataSource in Terelik Advertise but this is not work in my condition.
    please help me without using ObjectDataSource control.

    please check below

    in .ASPX code
    <telerik:RadGrid ID="gvDetails" Skin="Outlook" BorderWidth="0" AllowFilteringByColumn="True"
                                     runat="server" AutoGenerateColumns="False" ShowStatusBar="true" EnableLinqExpressions="false"      
                                    OnSortCommand="gvDetails_SortCommand"  onupdatecommand="gvDetails_UpdateCommand" oneditcommand="gvDetails_EditCommand"
                                     OnItemDeleted="gvDetails_ItemDeleted" OnSelectedIndexChanged="gvDetails_SelectCommand"  oncancelcommand="gvDetails_CancelCommand"   onprerender="gvDetails_PreRender"  >
                                    <MasterTableView AllowFilteringByColumn="true" DataKeyNames="ID" TableLayout="Fixed">
                                            <div style="font-weight: bold; color: Red;">
                                                No Record Found.</div>
                                            <telerik:GridTemplateColumn UniqueName="Description" DefaultInsertValue="" HeaderText="Description"
                                               DataField="Description"  SortExpression="Description" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains"
                                                AllowFiltering="true" FilterControlWidth="99%" HeaderStyle-Width="70%">                                
                                                    <asp:Label ID="lbltasktype" runat="server" Text='<%# Eval("Description")%>'> </asp:Label>
                                                    <asp:TextBox ID="txtstatusname1" runat="server" SkinID="textbox" Text='<%# Eval("Description")%>'
                                            <telerik:GridEditCommandColumn UniqueName="EditCommandColumn"  />
                                            <telerik:GridButtonColumn ConfirmText="Delete this product?" ButtonType="ImageButton"
                                            CommandName="Delete" Text="Delete" UniqueName="DeleteColumn">
                                            <HeaderStyle Width="20px" />
                                            <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" />
                               <%--     <ClientSettings AllowColumnsReorder="True">
                                        <Resizing AllowColumnResize="true" />

    in ASPX.CS  Code
    protected void gvDetails_ItemDeleted(object source, Telerik.Web.UI.GridDeletedEventArgs e)
            GridDataItem editedItem = (GridDataItem)e.Item;
            String id = editedItem.GetDataKeyValue("ID").ToString();
            lblMsg.Text = "";
            DAL.DAL obj = new DAL.DAL(DAL.DAL.DBType.SqlServer, sConString);
            if (Request.QueryString["prbls"] == "Severity")
                String strdel = "UPDATE EMRProblemsSeverity SET Active=0 WHERE Id=" + id;
                obj.ExecuteNonQuery(CommandType.Text, strdel);

            else if (Request.QueryString["prbls"] == "Context")
                String strdel = "UPDATE EMRProblemsContext SET Active=0 WHERE Id=" + id;
                obj.ExecuteNonQuery(CommandType.Text, strdel);
            else if (Request.QueryString["prbls"] == "Quality")
                String strdel = "UPDATE EMRProblemsQuality SET Active=0 WHERE Id=" + id;
                obj.ExecuteNonQuery(CommandType.Text, strdel);
            else if (Request.QueryString["prbls"] == "Duration")
                String strdel = "UPDATE EMRProblemsDuration SET Active=0 WHERE Id=" + id;
                obj.ExecuteNonQuery(CommandType.Text, strdel);
            else if (Request.QueryString["prbls"] == "Location")
                String strdel = "UPDATE EMRProblemsLocation SET Active=0 WHERE Id=" + id;
                obj.ExecuteNonQuery(CommandType.Text, strdel);
            else if (Request.QueryString["prbls"] == "Condition")
                String strdel = "UPDATE EMRProblemsCondition SET Active=0 WHERE Id=" + id;
                obj.ExecuteNonQuery(CommandType.Text, strdel);
    but delete event not fired.
    how it will fired the delete event.

    Please help me as soon as possible because i need urgently.
    Help me urgently.
    thanks you
    Jiten Kumar
    Akhil Systems Pvt Ltd.
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 03 Feb 2011 Link to this post

    Hello Jiteni,

    If you want to delete grid row from code behind attach 'DeleteCommand' to RadGrid and write code to delete the row.

    <telerik:RadGrid ID="RadGrid1" ondeletecommand="RadGrid1_DeleteCommand">

    protected void RadGrid1_DeleteCommand(object sender, GridCommandEventArgs e)
             //write code here

  3. Caoimhin
    Caoimhin avatar
    1 posts
    Member since:
    May 2013

    Posted 13 Jul 2018 Link to this post


    I have two buttons one called delete and one called exclude. They work independently but wont work together. I want them to do the exact same thing . The only difference is that in the viewAll store procedure for delete i have set where IsDeleted =0 so its not visible.The  Exclude is visible and just puts a line through the record and you have the option in the edit to restore the record.

    You cannot have two ondeleteCommands

Back to Top