如何检查中继内的复选框在结合时accordingto价值? [英] how to check the checkbox inside the repeater at binding time accordingto value?
问题描述
我有一个中继器和里面我有一个复选框。现在我想根据列值(0/1)进行检查。我已经通过中继器的ItemDataBound事件试了一下。它是什么做的,如果行的值为1那么它检查了所有的复选框,如果第一个复选框的勾选,那么它的所有选中。
我的code是: -
`
< TD ALIGN =中心>
< ASP:复选框ID =CHK=服务器/>
< / TD>
< / TR>
< / ItemTemplate中>
< / ASP:直放站>`
该事件的ItemDataBound code是: -
保护无效rp_ItemDataBound(对象发件人,RepeaterItemEventArgs E)
{
DataTable的DT =新的DataTable();
DT = obj.abc(ID);
如果(dt.Rows.Count大于0)
{
复选框CHK =(复选框)(e.Item.FindControl(CHK));
如果(CHK!= NULL)
{ 如果(Convert.ToInt32(dt.Rows [0] [XYZ])== Convert.ToInt32(0))
{
chk.Checked = FALSE;
}
其他
{
chk.Checked = TRUE; }
} }}
有很多方法可以做到这一点。
-
您可以编写内联ASP.NET:
< ASP:复选框ID ='isMarried'RUNAT =服务器
选中='<%#Convert.ToBool(EVAL(IsMarried))?真:假%GT;' /> -
正如你所提到的,你可以使用
repeater_ItemDataBound
找到每行的复选框,并相应地设置它的值:保护无效repeater_ItemDataBound(对象发件人,RepeaterItemEventArgs E)
{
人人=(人)e.Item; // e.Item是该行的datasoruce
如果(person.IsMarried)
{
复选框isMarried =(复选框)(e.Item.FindControl(isMarried));
isMarried.Checked = TRUE;
}
} -
另一种方式可能是在一个隐藏字段注入布尔状态(这里,婚姻状态),并将其发送给客户端,然后在客户端,使用jQuery(或任何其他JavaScript框架),更新
:检查箱根据这些隐藏字段的值选中状态
I have a repeater and inside it i have a checkbox. Now i want to check it according to columns value(0/1). I have tried it through the itemDataBound event of the repeater. what its doing if the rows has value 1 then its checked all checkbox and if first checkbox is unchecked then its unchecked all. my code is:- `
<td align="center">
<asp:CheckBox ID="chk" runat="server" />
</td>
</tr>
</ItemTemplate>
</asp:Repeater>`
The ItemDataBound events code is :-
protected void rp_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
DataTable dt = new DataTable();
dt = obj.abc(id);
if (dt.Rows.Count > 0)
{
CheckBox chk = (CheckBox)(e.Item.FindControl("chk"));
if (chk != null)
{
if (Convert.ToInt32(dt.Rows[0]["xyz"]) == Convert.ToInt32("0"))
{
chk.Checked = false;
}
else
{
chk.Checked = true;
}
}
}
}
There are many ways to do that.
You can write inline ASP.NET:
<asp:CheckBox id='isMarried' runat='server' Checked='<%# Convert.ToBool(Eval("IsMarried")) ? true : false %>' />
As you have mentioned, you can use
repeater_ItemDataBound
to find the check-box of each row, and set its value accordingly:protected void repeater_ItemDataBound(object sender, RepeaterItemEventArgs e) { Person person = (Person)e.Item; // e.Item is the datasoruce of the row if (person.IsMarried) { CheckBox isMarried = (CheckBox)(e.Item.FindControl("isMarried")); isMarried.Checked = true; } }
Another way could be to inject the Boolean state (here, the marriage state) in a hidden field and send it to the client, then on client-side, using jQuery (or any other JavaScript framework), update check-boxes' checked state according to the value of those hidden fields:
这篇关于如何检查中继内的复选框在结合时accordingto价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!