获取动态生成checkbox的id

sk1078 sk1078 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
CodeFile="No.aspx.cs" Inherits="Guest_No"
Title="" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<asp:DropDownList ID="Year" runat="server">
<asp:ListItem Value="0">请选择年</asp:ListItem>
<asp:ListItem>2012</asp:ListItem>
<asp:ListItem>2013</asp:ListItem>
<asp:ListItem>2014</asp:ListItem>
<asp:ListItem>2015</asp:ListItem>
<asp:ListItem>2016</asp:ListItem>
<asp:ListItem>2017</asp:ListItem>
<asp:ListItem>2018</asp:ListItem>
<asp:ListItem>2019</asp:ListItem>
<asp:ListItem>2020</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="Month" runat="server">
<asp:ListItem Value="0">请选择月</asp:ListItem>
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
<asp:ListItem>6</asp:ListItem>
<asp:ListItem>7</asp:ListItem>
<asp:ListItem>8</asp:ListItem>
<asp:ListItem>9</asp:ListItem>
<asp:ListItem>10</asp:ListItem>
<asp:ListItem>11</asp:ListItem>
<asp:ListItem>12</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="确定" OnClick="Button1_Click" />
<asp:Label ID="Label1" runat="server"></asp:Label>
<div runat="server" id="div1" visible="false">
<asp:Table ID="Table1" runat="server" BorderColor="Black" BorderWidth="1px" GridLines="Both">
</asp:Table>
<asp:Button ID="Button2" runat="server" Text="提交" OnClick="Button2_Click" /><asp:Button
ID="Button3" runat="server" Text="重置" />
</div>
</asp:Content>
 protected void Button1_Click(object sender, EventArgs e)
{
int i, j, k;
int year = Convert.ToInt32(Year.SelectedValue.ToString());
int month = Convert.ToInt32(Month.SelectedValue.ToString());
if (year.ToString() == "0" || month.ToString() == "0")
{
Label1.Text = "请选择年月";
}
else if (year.ToString() == "0")
{
Label1.Text = "请选择年";
}
else if (month.ToString() == "0")
{
Label1.Text = "请选择月";
}
else
{
int day = Convert.ToInt32(DateTime.DaysInMonth(year, month).ToString());
DateTime firstDay = new DateTime(year, month, 1);
DateTime lostDay = new DateTime(year, month, DateTime.DaysInMonth(year, month));
TableRow tRow1 = new TableRow();
Table1.Rows.Add(tRow1);
TableCell Cell1 = new TableCell();
Cell1.Text = "号";
tRow1.Cells.Add(Cell1);
for (i = 1; i <= day; i++)
{
TableCell tCell1 = new TableCell();
tCell1.Text = i.ToString();
tRow1.Cells.Add(tCell1);
}
TableRow tRow2 = new TableRow();
Table1.Rows.Add(tRow2);
TableCell Cell2 = new TableCell();
Cell2.Text = "1,2";
tRow2.Cells.Add(Cell2);
for (i = 1; i <= day; i++)
{
TableCell tCell2 = new TableCell();
tRow2.Cells.Add(tCell2);
CheckBox CB = new CheckBox();
CB.ID = "cb1" + i.ToString();
tCell2.Controls.Add(CB);
}
}

怎么获取checkbox的id,使用了母板页,这是内容页
...全文

相关推荐

评论 11
收藏 已收藏
分享
返回顶部
sk1078
.NET社区 62,274 成员 668,968 内容