aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
<asp:Panel ID="panelFilter" runat="server">
</asp:Panel>
</asp:Content>
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
CheckBoxList objCheckbox1 = new CheckBoxList();
objCheckbox1.ID = "objCheckbox1";
objCheckbox1.AutoPostBack = true;
objCheckbox1.SelectedIndexChanged += SelectedIndexChanged;
CheckBoxList objCheckbox2 = new CheckBoxList();
objCheckbox2.ID = "objCheckbox2";
objCheckbox2.AutoPostBack = true;
objCheckbox2.SelectedIndexChanged += SelectedIndexChanged;
objCheckbox1.Items.Add(new ListItem("Items 1", "Items 1"));
objCheckbox1.Items.Add(new ListItem("Items 2", "Items 2"));
objCheckbox1.Items.Add(new ListItem("Items 3", "Items 3"));
objCheckbox2.Items.Add(new ListItem("Items 4", "Items 4"));
objCheckbox2.Items.Add(new ListItem("Items 5", "Items 5"));
objCheckbox2.Items.Add(new ListItem("Items 6", "Items 6"));
panelFilter.Controls.Add(objCheckbox1);
panelFilter.Controls.Add(objCheckbox2);
}
protected void SelectedIndexChanged(object sender, EventArgs e)
{
CheckBoxList obj = sender as CheckBoxList;
List<ListItem> selected = obj.Items.Cast<ListItem>()
.Where(li => li.Selected)
.ToList();
}
}
}
No comments:
Post a Comment