使用c#在面板中永久删除信息

时间:2016-09-07 03:26:05

标签: c# asp.net

我有使用按钮的asp代码。当用户点击该按钮时,它将从该面板中删除信息。

asp文件代码:

<asp:Button Id="btnremoveadd" runat="server" CssClass="btn btn-danger" Text="Remove" CommandArgument='<%#Eval("Id") %>' CommandName="Delete" />

在aspx.cs文件代码中,我不知道如何使用它来删除信息。 我有编辑,创建和取消按钮。请参阅下面的命令,但不是删除按钮:

 protected void dlItems_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        int id = Convert.ToInt32(e.CommandArgument);
        Panel pnlAddressLabel = (Panel)e.Item.FindControl("pnlAddressLabel");
        Panel pnlAddressEdit = (Panel)e.Item.FindControl("pnlAddressEdit");
        Panel pnlAddressCreate = (Panel)e.Item.FindControl("pnlAddressCreate");
        Panel pnlAddressAdd = (Panel)e.Item.FindControl("pnlAddressAdd");

        switch (e.CommandName)
        {
            case ("Edit"):
                pnlAddressLabel.Visible = false;
                pnlAddressEdit.Visible = true;

                ((TextBox)pnlAddressEdit.FindControl("txtContName")).Text = ((Label)pnlAddressLabel.FindControl("lblcontactname")).Text;
                ((TextBox)pnlAddressEdit.FindControl("txtContNum")).Text = ((Label)pnlAddressLabel.FindControl("lblcontactnum")).Text;
                ((TextBox)pnlAddressEdit.FindControl("txtStreet")).Text = ((Label)pnlAddressLabel.FindControl("lblStreet")).Text;
                ((TextBox)pnlAddressEdit.FindControl("txtStreet2")).Text = ((Label)pnlAddressLabel.FindControl("lblStreet2")).Text;
                ((TextBox)pnlAddressEdit.FindControl("txtCity")).Text = ((Label)pnlAddressLabel.FindControl("lblCity")).Text;
                ((TextBox)pnlAddressEdit.FindControl("txtPostalCode")).Text = ((Label)pnlAddressLabel.FindControl("lblPostalCode")).Text;
                PopulateCountries((DropDownList)pnlAddressEdit.FindControl("drpCountry"), ((Label)pnlAddressLabel.FindControl("lblCountry")).Text, ((DropDownList)pnlAddressEdit.FindControl("drpState")), ((Label)pnlAddressLabel.FindControl("lblState")).Text);
                break;
            case ("Delete"):

                break;
            case ("Update"):
                UpdateContact(pnlAddressEdit);
                BindDeliveryAddress();
                pnlAddressLabel.Visible = true;
                pnlAddressEdit.Visible = false;
                ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "EditAddressAlert()", true);
                break;
            case ("Cancel"):
                pnlAddressLabel.Visible = true;
                pnlAddressEdit.Visible = false;
                break;
            case ("Add"):
                pnlAddressAdd.Visible = false;
                pnlAddressCreate.Visible = true;
                PopulateCountries((DropDownList)pnlAddressCreate.FindControl("drpCountry"), "", ((DropDownList)pnlAddressCreate.FindControl("drpState")), "");
                break;
            case ("Create"):
                if (CreateContact(pnlAddressCreate))
                {
                    BindDeliveryAddress();
                    pnlAddressAdd.Visible = true;
                    pnlAddressCreate.Visible = false;
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "AddAddressAlert()", true);
                }
                else
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "DuplicateAddressAlert()", true);
                break;
            case ("CancelCreate"):
                pnlAddressAdd.Visible = true;
                pnlAddressCreate.Visible = false;
                break;
        }
    }

0 个答案:

没有答案