检查项目时如何获取CheckBox列表项的ID [英] How to get ID of CheckBox list items when I check its item

查看:94
本文介绍了检查项目时如何获取CheckBox列表项的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我检查项目时如何获取CheckBox列表项的ID,我在winddow应用程序中使用c#请帮助

How to get ID of CheckBox list items when I check its item , I use c# in winddow application Please help

推荐答案

查看此示例:



See this example :

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
 <head runat="server">
 <title></title>
 </head>
 <body>
 <form id="form1" runat="server">
 <div>
 <asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="True" Height="31px" OnSelectedIndexChanged="CheckBoxList1_SelectedIndexChanged" Width="140px">
 <asp:ListItem>Adrotator</asp:ListItem>
 <asp:ListItem>BulletedList</asp:ListItem>
 <asp:ListItem>Button</asp:ListItem>
 <asp:ListItem>Calendar</asp:ListItem>
 <asp:ListItem>DropDownList</asp:ListItem>
 </asp:CheckBoxList>
 <br />
 </div>
 <asp:Label ID="Label1" runat="server"></asp:Label>
 </form>
 </body>
 </html>
Codebehind
using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Web;
 using System.Web.UI;
 using System.Web.UI.WebControls;

public partial class Default3 : System.Web.UI.Page


{
  protected void Page_Load(object sender, EventArgs e)



{

}
  protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)



{
  foreach (ListItem item in CheckBoxList1 .Items)



{
  if (item.Selected)



{

Label1.Text += item.Text;

}

}

}

}


这篇关于检查项目时如何获取CheckBox列表项的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆