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

need help To Delete item

3 Answers 109 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Yong
Top achievements
Rank 2
Yong asked on 11 Sep 2008, 07:14 AM
Hi,

Need help on deleting records off my Radgrid, i have tried to use client side delete and it works but upon page refresh and i add new product the row which i deleted earlier is not deleted?

How do i delete rows from my radgrid?

I am using datable

Code Behind

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;

[System.ComponentModel.Description("Management")]

public partial class Management : System.Web.UI.UserControl
{

    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected void ProductAddButton_Click(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();

        dt.Columns.Add(new DataColumn("ProdType"));
        dt.Columns.Add(new DataColumn("ProdUnitUser"));

        DataRow dr;

        GridDataItemCollection dtCol = ProductTable.Items;
        foreach (GridDataItem item in dtCol)
        {
            dr = dt.NewRow();
            dr["ProdType"] = item["ProdType"].Text;
            dr["ProdUnitUser"] = item["ProdUnitUser"].Text;
            dt.Rows.Add(dr);
        }

        dr = dt.NewRow();
        dr["ProdType"] = ProdTypeComboBox.SelectedItem.Text.ToString();
        dr["ProdUnitUser"] = ProdUnitUserNumTxtBox.Text.ToString();

        dt.Rows.Add(dr);
        ProductTable.DataSource = dt.DefaultView;
        ProductTable.DataBind();
    }

    protected void ConfirmButton_Click(object sender, EventArgs e)
    {
       
        DataTable du = new DataTable();
        ProductTable.DataSource = du;
        ProductTable.DataBind();

            DataTable dt1 = new DataTable();

            dt1.Columns.Add(new DataColumn("ProdType"));
            dt1.Columns.Add(new DataColumn("ProdUnitUser"));
            dt1.Columns.Add(new DataColumn("ProdAmt"));

            DataRow dr1;

            GridDataItemCollection dtCol1 = ConfirmTable.Items;
            foreach (GridDataItem item in dtCol1)
            {
                dr1 = dt1.NewRow();
                dr1["ProdType"] = item["ProdType"].Text;
                dr1["ProdUnitUser"] = item["ProdUnitUser"].Text;
                dr1["ProdAmt"] = item["ProdAmt"].Text;
                dt1.Rows.Add(dr1);
            }

            dr1 = dt1.NewRow();
            dr1["ProdType"] = ProdTypeComboBox.SelectedItem.Text.ToString();
            dr1["ProdUnitUser"] = ProdUnitUserNumTxtBox.Text.ToString();
            dr1["ProdAmt"] = ProdAmtNumTxtBox.Text.ToString();

            dt1.Rows.Add(dr1);
            ConfirmTable.DataSource = dt1.DefaultView;
            ConfirmTable.DataBind();
    }

    protected void SubmitButton_Click(object sender, EventArgs e)
    {
        Response.Redirect("http://dev1:8080/");
    }
  
    protected void ProdTypeComboBox_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        if (ProdTypeComboBox.SelectedValue.ToString() == "CopyLog")
        {
            Label1.Text = "Units";
        }
        else
        {
            Label1.Text = "Users";
        }
    }

    protected void ProductTable_DeleteCommand(object source, GridCommandEventArgs e)
    {
        //GridDataItem dataItem = (GridDataItem)e.Item;
        //String ProdType = dataItem.GetDataKeyValue("ProdType").ToString();
    }
}

UI


<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Management.ascx.cs" Inherits="Management" %>
<%@ Register Assembly="Telerik.Web.UI, Version=2008.2.826.20, Culture=Neutral, PublicKeyToken=121fae78165ba3d4" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

<telerik:RadFormDecorator ID="RadFormDecorator1" runat="server" Skin="Web20"  />
<telerik:RadAjaxPanel ID="RadAjaxPanel3" runat="server" Height="200px" Width="700px">
   
<table style="width: 550px">
      
        <tr>
            <td style="width: 95px">
            <asp:Label ID="NameLbl" runat="server" Text="Name"></asp:Label></td>
            <td style="width: 100px">
            <telerik:RadTextBox ID="NameTxtBox" runat="server"></telerik:RadTextBox></td>
            <td rowspan="11" style="width: 30px">
            </td>
           
            <td style="width: 95px">
            <asp:Label ID="CityLbl" runat="server" Text="City"></asp:Label></td>
            <td style="width: 100px">
            <telerik:RadTextBox ID="CityTxtBox" runat="server"></telerik:RadTextBox>
            </td>
       </tr>
      
        <tr>
            <td style="width: 95px">
            <asp:Label ID="ContactPersonLbl" runat="server" Text="Contact Person"></asp:Label></td>
            <td style="width: 100px">
            <telerik:RadTextBox ID="ContactPersonTxtBox" runat="server"></telerik:RadTextBox>
            </td>
           
            <td style="width: 95px">
            <asp:Label ID="StateLbl" runat="server" Text="State"></asp:Label></td>
            <td style="width: 100px">
            <telerik:RadTextBox ID="StateTxtBox" runat="server"></telerik:RadTextBox></td>
        </tr>
       
        <tr>
            <td style="width: 95px">
            <asp:Label ID="ContactNoLbl" runat="server" Text="Contact No."></asp:Label>
            </td>
           
            <td style="width: 100px">
            <telerik:RadTextBox ID="ContactNoTxtBox" runat="server"></telerik:RadTextBox>
            </td>
           
            <td style="width: 95px">
            <asp:Label ID="PostCodeLbl" runat="server" Text="Post Code"></asp:Label>
            </td>
           
            <td style="width: 100px">
            <telerik:RadTextBox ID="PostCodeTxtBox" runat="server"></telerik:RadTextBox>
            </td>
        </tr>
       
        <tr>
            <td style="width: 95px">
            <asp:Label ID="FaxNoLbl" runat="server" Text="Fax No."></asp:Label>
            </td>
           
            <td style="width: 100px">
            <telerik:RadTextBox ID="FaxNoTxtBox" runat="server"></telerik:RadTextBox>
            </td>
           
            <td style="width: 95px">
            <asp:Label ID="EMailLbl" runat="server" Text="E-Mail"></asp:Label>
            </td>
           
            <td style="width: 100px">
            <telerik:RadTextBox ID="EMailTxtBox" runat="server"></telerik:RadTextBox>
            </td>
        </tr>
       
        <tr>
            <td style="width: 95px">
            <asp:Label ID="AddressLbl" runat="server" Text="Address"></asp:Label>
            </td>
           
            <td style="width: 100px">
            <telerik:RadTextBox ID="AddressTxtBox" runat="server"></telerik:RadTextBox>
            </td>
           
            <td style="width: 95px">
            <asp:Label ID="ContractNoLbl" runat="server" Text="Contract No."></asp:Label>
            </td>
           
            <td style="width: 100px">
            <telerik:RadTextBox ID="ContractNotxtBox" runat="server"></telerik:RadTextBox>
            </td>
        </tr>
       
        <tr>
            <td colspan="2">
                <br />
            </td>
           
            <td colspan="2" rowspan="3">
            </td>
        </tr>
       
        <tr>
            <td style="width: 95px">
            <asp:Label ID="DateLbl" runat="server" Text="Date Start"></asp:Label>
            </td>
           
            <td style="width: 100px">
            <telerik:RadDatePicker ID="DateStartPicker" runat="server" Width="125px">
                <Calendar runat="server" UseColumnHeadersAsSelectors="False" UseRowHeadersAsSelectors="False" ViewSelectorText="x">
                </Calendar>
            </telerik:RadDatePicker>
            </td>
        </tr>
       
        <tr>
            <td colspan="2">
                <br />
            </td>
        </tr>
       
        <tr>
            <td style="width: 95px">
            <asp:Label ID="ProdTypeLbl" runat="server" Text="Product Type"></asp:Label>
            </td>
            <td style="width: 100px">
            <telerik:RadComboBox ID="ProdTypeComboBox" runat="server" Width="126px" AutoPostBack="True" OnSelectedIndexChanged="ProdTypeComboBox_SelectedIndexChanged">
                <Items>
                    <telerik:RadComboBoxItem runat="server" Text="CopyLog" Value="CopyLog" Selected="True" />
                    <telerik:RadComboBoxItem runat="server" Text="FaxLog" Value="FaxLog" />
                    <telerik:RadComboBoxItem runat="server" Text="PrintLog" Value="PrintLog" />
                    <telerik:RadComboBoxItem runat="server" Text="TeleLog" Value="TeleLog" />
                </Items>
            <CollapseAnimation Duration="200" Type="OutQuint" />
            </telerik:RadComboBox>
            </td>
           
            <td style="width: 95px">
            <asp:Label ID="Label1" runat="server" Text="Units"></asp:Label>
            </td>
           
            <td style="width: 100px">
            <telerik:RadNumericTextBox ID="ProdUnitUserNumTxtBox" runat="server" Type="Number" Width="125px">
            <NumberFormat DecimalDigits="0" /></telerik:RadNumericTextBox>
            </td>
        </tr>
       
        <tr>
            <td colspan="2">
                <br />
            </td>
           
            <td colspan="2" rowspan="2">
            </td>
        </tr>
       
        <tr>
            <td style="width: 95px">
            </td>
           
            <td style="width: 100px">
            <asp:Button ID="ProductAddButton" runat="server" Text="Add Product" OnClick="ProductAddButton_Click" UseSubmitBehavior="False"/>
            </td>
        </tr>
       
</table><br />

<telerik:RadGrid ID="ProductTable" runat="server" AutoGenerateColumns="False" Skin="Hay" Width="530px" GridLines="None" OnDeleteCommand="ProductTable_DeleteCommand">

<MasterTableView GridLines="None" DataKeyNames="ProdType">
    <RowIndicatorColumn>
        <HeaderStyle Width="20px" />
    </RowIndicatorColumn>
    <ExpandCollapseColumn>
        <HeaderStyle Width="20px" />
    </ExpandCollapseColumn>
    <Columns>
        <telerik:GridBoundColumn DataField="ProdType" HeaderText="Product Type" UniqueName="ProdType"></telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="ProdUnitUser" HeaderText="Product Unit/Users" UniqueName="ProdUnitUser"></telerik:GridBoundColumn>
        <telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="column" ConfirmText="1 Record Will Be Deleted, Confirm?" ConfirmTitle="Deleting record"></telerik:GridButtonColumn>
    </Columns>
</MasterTableView>

<FilterMenu EnableTheming="True" Skin="Telerik">
<CollapseAnimation Duration="200" Type="OutQuint" />
</FilterMenu>
    <ClientSettings>
        <Selecting AllowRowSelect="True" />
    </ClientSettings>
</telerik:RadGrid><br />

<table>

    <tr>
        <td style="width: 100px">
        <asp:Label ID="AmountLbl" runat="server" Text="Amount"></asp:Label>
        </td>
       
        <td style="width: 100px">
        <telerik:RadNumericTextBox ID="ProdAmtNumTxtBox" runat="server" Culture="English (United States)" Width="125px">
        <NumberFormat DecimalDigits="0" /></telerik:RadNumericTextBox>
        </td>
       
        <td style="width: 30px" rowspan="1">
        </td>
       
        <td style="width: 100px">
        <asp:Button ID="ConfirmButton" runat="server" Text="Confirm" OnClick="ConfirmButton_Click"/>
        </td>
    </tr>
   
</table><br />

<telerik:RadGrid ID="ConfirmTable" runat="server" AutoGenerateColumns="False" GridLines="None" Skin="Hay" Width="530px" PageSize="5">
<MasterTableView AllowAutomaticDeletes="True" DataKeyNames="ProdType,ProdUnitUser,ProdAmt">
<RowIndicatorColumn>
<HeaderStyle Width="20px" />
</RowIndicatorColumn>
<ExpandCollapseColumn>
<HeaderStyle Width="20px" />
</ExpandCollapseColumn>
    <Columns>
        <telerik:GridBoundColumn HeaderText="Product Type" UniqueName="ProdType" DataField="ProdType">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn HeaderText="Product Unit/User" UniqueName="ProdUnitUser" DataField="ProdUnitUser">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn HeaderText="Amount" UniqueName="ProdAmt" DataField="ProdAmt">
        </telerik:GridBoundColumn>
        <telerik:GridClientDeleteColumn ConfirmText="Are you sure you want to delete the selected row?" ConfirmTitle="Delete Record" Text="Delete" UniqueName="column"/>
    </Columns>
</MasterTableView>
<FilterMenu EnableTheming="True" Skin="Hay">
<CollapseAnimation Duration="200" Type="OutQuint" />
</FilterMenu>
</telerik:RadGrid><br />
    <table>
    <tr>
        <td style="width: 200px">
            <br />
            <asp:Button ID="SubmitButton" runat="server" Text="Submit" OnClick="SubmitButton_Click"/></td>
    </tr>
</table>
</telerik:RadAjaxPanel>

Thank You In Advance

3 Answers, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 11 Sep 2008, 09:01 AM
Hi Yong,

I don't see where is the code that will delete the row from the table? Can you clarify?

Sincerely yours,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Yong
Top achievements
Rank 2
answered on 11 Sep 2008, 09:18 AM
Found The Solution

Sorry
0
Yves
Top achievements
Rank 1
answered on 15 Nov 2008, 06:25 PM
Great, but what is your solution ?

Thanks.
Tags
Grid
Asked by
Yong
Top achievements
Rank 2
Answers by
Vlad
Telerik team
Yong
Top achievements
Rank 2
Yves
Top achievements
Rank 1
Share this question
or