checkbox在repeater中checked值无法改变
看这段实例<asp:RepeaterID="Repeater1"runat="server"><ItemTemplate><div><asp:TextBoxID="Tex...
看这段实例
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<div>
<asp:TextBox ID="TextBox2" runat="server" Text ='<%# Eval("name") %>'></asp:TextBox>
<asp:CheckBox ID="CheckBox1" runat="server" Text="测试" />
</div>
</ItemTemplate>
</asp:Repeater>
cs代码
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt=new DataTable ();
dt.Columns.Add ("name");
DataRow dr=dt.NewRow ();
dr[0]="123";
dt.Rows.Add (dr);
this.Repeater1.DataSource = dt;
this.Repeater1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
CheckBox cbx=(CheckBox)this.Repeater1.Items[0].FindControl("CheckBox1");
TextBox1.Text = cbx.Checked.ToString();
}
无论怎么单击checkbox1 在textbox1中都显示的checked值都为false 展开
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<div>
<asp:TextBox ID="TextBox2" runat="server" Text ='<%# Eval("name") %>'></asp:TextBox>
<asp:CheckBox ID="CheckBox1" runat="server" Text="测试" />
</div>
</ItemTemplate>
</asp:Repeater>
cs代码
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt=new DataTable ();
dt.Columns.Add ("name");
DataRow dr=dt.NewRow ();
dr[0]="123";
dt.Rows.Add (dr);
this.Repeater1.DataSource = dt;
this.Repeater1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
CheckBox cbx=(CheckBox)this.Repeater1.Items[0].FindControl("CheckBox1");
TextBox1.Text = cbx.Checked.ToString();
}
无论怎么单击checkbox1 在textbox1中都显示的checked值都为false 展开
展开全部
.cs:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add("name");
DataRow dr = dt.NewRow();
dr[0] = "123";
dt.Rows.Add(dr);
this.Repeater1.DataSource = dt;
this.Repeater1.DataBind();
}
CheckBox cbx = (CheckBox)this.Repeater1.Items[0].FindControl("CheckBox1");
TextBox txt1 = (TextBox)this.Repeater1.Items[0].FindControl("TextBox1");
txt1.Text = cbx.Checked.ToString();
}
.aspx:
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<div>
<asp:TextBox ID="TextBox1" runat="server" Text ='<%# Eval("name") %>'></asp:TextBox>
<asp:CheckBox ID="CheckBox1" AutoPostBack="true" runat="server" Text="测试" />
</div>
</ItemTemplate>
</asp:Repeater>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add("name");
DataRow dr = dt.NewRow();
dr[0] = "123";
dt.Rows.Add(dr);
this.Repeater1.DataSource = dt;
this.Repeater1.DataBind();
}
CheckBox cbx = (CheckBox)this.Repeater1.Items[0].FindControl("CheckBox1");
TextBox txt1 = (TextBox)this.Repeater1.Items[0].FindControl("TextBox1");
txt1.Text = cbx.Checked.ToString();
}
.aspx:
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<div>
<asp:TextBox ID="TextBox1" runat="server" Text ='<%# Eval("name") %>'></asp:TextBox>
<asp:CheckBox ID="CheckBox1" AutoPostBack="true" runat="server" Text="测试" />
</div>
</ItemTemplate>
</asp:Repeater>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询