search this blog [2700+ asp.net c# examples]

Loading...

Delete RadioButtonList list item programmatically in asp.net

asp.net RadioButtonList: how to remove list item programmatically
RadioButtonListRemoveItem.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RadioButtonListRemoveItem.aspx.cs" Inherits="RadioButtonListRemoveItem" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>asp.net RadioButtonList: how to remove list item programmatically</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Fuchsia">RadioButtonList: Remove List Item</h2>
        <asp:RadioButtonList 
            ID="RadioButonList1"
            runat="server"
            RepeatColumns="3"
            ForeColor="DarkMagenta"
            BackColor="Orange"
            BorderWidth="2"
            BorderColor="Crimson"
            >
            <asp:ListItem>TreeView</asp:ListItem>
            <asp:ListItem>Menu</asp:ListItem>
            <asp:ListItem>ListItem</asp:ListItem>
            <asp:ListItem>DropDownList</asp:ListItem>
            <asp:ListItem>CheckBoxList</asp:ListItem>
        </asp:RadioButtonList>
        <br /><br />
        <asp:Button 
            ID="Button1"
            runat="server"
            Font-Bold="true"
            ForeColor="DodgerBlue"
            Text="Remove selected item"
            OnClick="Button1_Click"
            />
    </div>
    </form>
</body>
</html>
RadioButtonListRemoveItem.aspx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class RadioButtonListRemoveItem : System.Web.UI.Page
{
    protected void Button1_Click(object sender, EventArgs e)
    {
        RadioButonList1.Items.Remove(RadioButonList1.SelectedItem);
    }
}








Related asp.net example