在线等,repeater 中怎样给checkboxlist选中值 20
3个回答
展开全部
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
((CheckBox)e.Item.FindControl("盯蠢派check")).Checked = true;
}
}
------------------------
完成如下
aspx文件:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="t.aspx.cs" Inherits="bangsotest_t" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>凯贺
<form id="form1" runat="server">
<div>
<asp:Repeater ID="Repeater1" runat="server" onitemdatabound="Repeater1_ItemDataBound">
<ItemTemplate>
<asp:CheckBox ID="check" runat="server" />
</ItemTemplate>
</asp:Repeater>
</div>
</form>
</档亮body>
</html>
cs文件:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class bangsotest_t : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
IList<tclass> tl = new List<tclass>();
tclass t = new tclass();
t.Cid = "1";
tl.Add(t);
Repeater1.DataSource = tl;
Repeater1.DataBind();
}
private class tclass
{
private string cid;
public string Cid
{
get { return cid; }
set { cid = value; }
}
}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
tclass dv = (tclass)e.Item.DataItem;
if (dv.Cid == "1")
{
((CheckBox)e.Item.FindControl("check")).Checked = true;
}
}
}
}
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
((CheckBox)e.Item.FindControl("盯蠢派check")).Checked = true;
}
}
------------------------
完成如下
aspx文件:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="t.aspx.cs" Inherits="bangsotest_t" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>凯贺
<form id="form1" runat="server">
<div>
<asp:Repeater ID="Repeater1" runat="server" onitemdatabound="Repeater1_ItemDataBound">
<ItemTemplate>
<asp:CheckBox ID="check" runat="server" />
</ItemTemplate>
</asp:Repeater>
</div>
</form>
</档亮body>
</html>
cs文件:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class bangsotest_t : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
IList<tclass> tl = new List<tclass>();
tclass t = new tclass();
t.Cid = "1";
tl.Add(t);
Repeater1.DataSource = tl;
Repeater1.DataBind();
}
private class tclass
{
private string cid;
public string Cid
{
get { return cid; }
set { cid = value; }
}
}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
tclass dv = (tclass)e.Item.DataItem;
if (dv.Cid == "1")
{
((CheckBox)e.Item.FindControl("check")).Checked = true;
}
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
1.先用findControl(“州饥控扰则件ID”)方法找到repeater控件册李返里的checkboxlist
2. foreach (ListItem items in CheckBoxList1.Items
{
items.Selected = true;
}
2. foreach (ListItem items in CheckBoxList1.Items
{
items.Selected = true;
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
CheckBox cbox = (CheckBox)Repeater1.Items[i].FindControl("chkSelect");
chkSelect 是扒贺复选框的并此枝绝敏ID值.
chkSelect 是扒贺复选框的并此枝绝敏ID值.
参考资料: 自己动手 丰衣足食
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询