中继器和复选框 [英] repeater and checkboxes
本文介绍了中继器和复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
ASPX代码:
ASPX code:
<td class="field1"><asp:CheckBox ID="CheckBox1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "PersonnelSummary_Cleveland_Resident") %>'/></td>
<td class="field1"><asp:CheckBox ID="CheckBox2" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "PersonnelSummary_Present") %>' /></td>
<asp:Button ID="btnAddAnother" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Button") %>' CommandName='<%# DataBinder.Eval(Container.DataItem, "Button") %>' />
cs代码:
cs code:
public void Rptr_ItemCommand(Object source, RepeaterCommandEventArgs e)
{
int Total = Rptr.items.Count;
if (e.CommandName == "Add")
{
Total = Total + 1;
AddColumns();
foreach (Repeater item in Rptr.Items)
{
CheckBox PSR = ((CheckBox)item.FindControl("txtPSR"));
CheckBox PSP = ((CheckBox)item.FindControl("txtPSP"));
Button btnAdd = ((Button)item.FindControl("btnAddAnother"));
}
tb.Rows.Add(PSR,PSP, "Add");
}
else if (e.CommandName == "Remove")
{
Total = Total -1;
CheckBox PSR = ((CheckBox)item.FindControl("txtPSR"));
CheckBox PSP = ((CheckBox)item.FindControl("txtPSP"));
Button btnAdd = ((Button)item.FindControl("btnAddAnother"));
}
}
public void AddColumns()
{
tb.Columns.Add("PSR", typeof(bool));
tb.Columns.Add("PSP", typeof(bool));
tb.Columns.Add("Button")
}
public void ButtonAdd_Click(object sender, EvenetArgs args)
{
AddColumns();
tb.Rows.Add(bool, bool, "Add");
btnAddAnother.Visible = false;
}
我有两个问题:
P1:当用户单击添加按钮时,复选框出现错误.我将布尔值更改为1或0,以表示是非.当我单击复选框以查看是否更改时,答案是否定的.
P2:当用户单击以将其删除时,将删除动态创建的最上层
I have two problems:
P1: When a user click the add button, I get error on the check boxes. I change the bool to 1 or 0 it comes up true or false. When I click on the checkboxes to see if the change the answer is no.
P2: When the user click to remove it remove a dynamically created the very top
推荐答案
tb.Rows.Add(bool, bool, "Add");
这显然是行不通的.布尔是一种类型,而不是值.
This quite obviously won''t work. Bool is a type not a value.
这篇关于中继器和复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文