在我的网页上,我有 2 个文本框,它们分别将输入作为年份和月份。然后根据这些值从数据库表中检索一个称为工作日的列值。它的值是这种格式(111110011111001111100111110011)这里1表示工作日,0表示假期(可以是星期六或太阳或任何其他假期)。现在,根据这个检索到的值,我想显示 30/31(取决于月份天数)复选框,并且应该选中假期复选框并保持未选中状态。它应该是这样的 1 2 3 4 5 6 7.................................30 和它们下面的复选框。现在正在使用的代码仅在 1 下方显示 1 个复选框(这是第一个标题),然后下一个日期显示在转发器中,但复选框出现在下一行。你能告诉我问题吗?
代码背后
公共类 MyCheckBox { public bool IsChecked { get; 放; } }
public void search(object sender, EventArgs e) { string cnnString = "Server=localhost;Port=3307;Database=leavesystem;Uid=root;Pwd=ashish"; MySqlConnection cnx = new MySqlConnection(cnnString); cnx.Open(); string cmdText = "Select WorkingDays from calender where Year = '" + year.Value + "' and Month = '" + month.Value + "' "; MySqlCommand cmd = new MySqlCommand(cmdText, cnx); if (month.Value == " January || March || May || July || August || October || December ") { string str = Convert.ToString(cmd.ExecuteScalar()); List<MyCheckBox> list = new List<MyCheckBox>(); foreach (char c in str) list.Add(new MyCheckBox { IsChecked = c == '0' }); MyRepeater1.DataSource = list; MyRepeater1.DataBind(); } else if (month.Value == " April || June || September || November ") { string str = Convert.ToString(cmd.ExecuteScalar()); List<MyCheckBox> list = new List<MyCheckBox>(); foreach (char c in str) list.Add(new MyCheckBox { IsChecked = c == '0' }); MyRepeater2.DataSource = list; MyRepeater2.DataBind(); } else if (month.Value == " February ") { string str = Convert.ToString(cmd.ExecuteScalar()); List<MyCheckBox> list = new List<MyCheckBox>(); foreach (char c in str) list.Add(new MyCheckBox { IsChecked = c == '0' }); MyRepeater3.DataSource = list; MyRepeater3.DataBind(); } }
中继器看起来像这样
<asp:Repeater ID="MyRepeater" runat="server">
> <HeaderTemplate>
> <table width="100%" class="table" border="1" style="font: 8pt verdana">
> <tr>
> <%
> for (int i = 1; i <= 31; i++)
> {
> Response.Write("<td>" + i + "</td>");
> }
> %>
> </tr>
>
> </HeaderTemplate>
> <ItemTemplate>
> <tr>
> <td>
> <asp:CheckBox ID="CheckBox1" Checked='<%# Eval("IsChecked") %>' runat="server" />
> </td>
> </tr>
> </table>
> </ItemTemplate>
> </asp:Repeater>
<asp:Repeater ID="MyRepeater2" runat="server">
<HeaderTemplate>
<table width="100%" class="table" border="1" style="font: 8pt verdana">
<tr>
<% for (int i = 1; i <= 30; i++)
{
Response.Write("<td>" + i + "</td>");
} %>
</tr>
<tr>
</HeaderTemplate>
<ItemTemplate>
<td>
<asp:CheckBox ID="CheckBox1" Checked='<%# Eval("IsChecked") %>' runat="server" />
</td>
</ItemTemplate>
<FooterTemplate>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>
<asp:Repeater ID="MyRepeater3" runat="server">
<HeaderTemplate>
<table width="100%" class="table" border="1" style="font: 8pt verdana">
<tr>
<% for (int i = 1; i <= 28; i++)
{
Response.Write("<td>" + i + "</td>");
} %>
</tr>
<tr>
</HeaderTemplate>
<ItemTemplate>
<td>
<asp:CheckBox ID="CheckBox1" Checked='<%# Eval("IsChecked") %>' runat="server" />
</td>
</ItemTemplate>
<FooterTemplate>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>