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

Delete row from RadGrid whitout using ObjectDataSource

2 Answers 179 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jiten
Top achievements
Rank 1
Jiten asked on 02 Feb 2011, 01:37 PM
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.

And
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">
                                    <NoRecordsTemplate>
                                        <div style="font-weight: bold; color: Red;">
                                            No Record Found.</div>
                                    </NoRecordsTemplate>
                                    <Columns>
                                        <telerik:GridTemplateColumn UniqueName="Description" DefaultInsertValue="" HeaderText="Description"
                                           DataField="Description"  SortExpression="Description" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains"
                                            ShowFilterIcon="false"
                                            AllowFiltering="true" FilterControlWidth="99%" HeaderStyle-Width="70%">                                
                                            <ItemTemplate>
                                                <asp:Label ID="lbltasktype" runat="server" Text='<%# Eval("Description")%>'> </asp:Label>
                                            </ItemTemplate>
                                            <EditItemTemplate>                                   
                                                <asp:TextBox ID="txtstatusname1" runat="server" SkinID="textbox" Text='<%# Eval("Description")%>'
                                                    MaxLength="100"></asp:TextBox>
                                            </EditItemTemplate>                                
                                        </telerik:GridTemplateColumn>
                                        <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" />
                                    </telerik:GridButtonColumn>
                                    </Columns>
                                </MasterTableView>
                           <%--     <ClientSettings AllowColumnsReorder="True">
                                    <Resizing AllowColumnResize="true" />
                                </ClientSettings>--%>
                                </telerik:RadGrid>

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);
            BindSeverity();

        }
        else if (Request.QueryString["prbls"] == "Context")
        {
            String strdel = "UPDATE EMRProblemsContext SET Active=0 WHERE Id=" + id;
            obj.ExecuteNonQuery(CommandType.Text, strdel);
            BindContext();
        }
        else if (Request.QueryString["prbls"] == "Quality")
        {
            String strdel = "UPDATE EMRProblemsQuality SET Active=0 WHERE Id=" + id;
            obj.ExecuteNonQuery(CommandType.Text, strdel);
            BindQuality();
        }
        else if (Request.QueryString["prbls"] == "Duration")
        {
            String strdel = "UPDATE EMRProblemsDuration SET Active=0 WHERE Id=" + id;
            obj.ExecuteNonQuery(CommandType.Text, strdel);
            BindDuration();
        }
        else if (Request.QueryString["prbls"] == "Location")
        {
            String strdel = "UPDATE EMRProblemsLocation SET Active=0 WHERE Id=" + id;
            obj.ExecuteNonQuery(CommandType.Text, strdel);
            BindLocation();
        }
        else if (Request.QueryString["prbls"] == "Condition")
        {
            String strdel = "UPDATE EMRProblemsCondition SET Active=0 WHERE Id=" + id;
            obj.ExecuteNonQuery(CommandType.Text, strdel);
            BindCondition();
        }
    }
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 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 03 Feb 2011, 09:59 AM
Hello Jiteni,

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

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

C#:
protected void RadGrid1_DeleteCommand(object sender, GridCommandEventArgs e)
   {
         //write code here
   }

Thanks,
Princy.
0
Caoimhin
Top achievements
Rank 1
answered on 13 Jul 2018, 02:44 PM

Hi 

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

Tags
Grid
Asked by
Jiten
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Caoimhin
Top achievements
Rank 1
Share this question
or