前台
<asp:Repeater ID=
Repeater
runat=
server
OnItemDataBound=
Repeater
_ItemDataBound
>
<ItemTemplate>
<ul>
<li>
<%#Eval(
DepId
)%>
<%#Eval(
Name
)%></li></ul>
<asp:Repeater ID=
Repeater
runat=
server
>
<ItemTemplate>
<asp:CheckBox ID=
cb
runat=
server
Text=
<%#Eval(
RealName
)%>
/>
<asp:HiddenField ID=
hidId
Value=
<%#Eval(
UserId
)%>
runat=
server
/>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
後台
protected void Page_Load(object sender
EventArgs e)
{
if (!Page
IsPostBack)
{
CF
Model
Department modelDepartment = new CF
Model
Department()
CF
BLL
Department bllDepartment = new CF
BLL
Department()
DataSet ds = bllDepartment
GetAllList()
Repeater
DataSource = ds
Tables[
]
DefaultView;
Repeater
DataBind()
}
}
protected void Repeater
_ItemDataBound(object sender
RepeaterItemEventArgs e)
{
if (e
Item
ItemType == ListItemType
Item || e
Item
ItemType == ListItemType
AlternatingItem)
{
Repeater rp = (Repeater)e
Item
FindControl(
Repeater
)
string id = DataBinder
Eval(e
Item
DataItem
DepId
)
ToString()
//取得部門id
//根據當前部門的id從人員表中查找員工的數據
CF
Model
Users modelUsers = new CF
Model
Users()
CF
BLL
Users bllUsers = new CF
BLL
Users()
DataSet dsUsers = bllUsers
GetList(
DepId=
+ id)
rp
DataSource = dsUsers
Tables[
]
DefaultView;
rp
DataBind()
}
}
//提交培訓名單
protected void btnSubmit_Click(object sender
EventArgs e)
{
string trainPersonsId=
;
string trainPersonsNames=
;
for (int i =
; i < this
Repeater
Items
Count; i++)
{
Repeater rptPersons = (Repeater)this
Repeater
Items[i]
FindControl(
Repeater
)
for (int j =
; j < rptPersons
Items
Count; j++)
{
int id = Convert
ToInt
(((HiddenField)rptPersons
Items[j]
FindControl(
hidId
))
Value)
CheckBox cb = (CheckBox)rptPersons
Items[j]
FindControl(
cb
)
if (cb
Checked)
{
trainPersonsId += id +
;
trainPersonsNames += cb
Text
Trim() +
;
}
}
//foreach (RepeaterItem item in rptPersons
Items)
//{
// if (item
ItemType == ListItemType
Item || item
ItemType == ListItemType
AlternatingItem)
// {
// CheckBox cb = item
FindControl(
cb
) as CheckBox;
// if (cb
Checked)
// {
// trainPersonsNames += cb
Text +
|
;
// }
// }
}
if (trainPersonsId !=
)
{
//去除最後一個字符
trainPersonsId = trainPersonsId
Substring(
trainPersonsId
Length
)
}
if (trainPersonsNames !=
)
{
//去除最後一個字符
trainPersonsNames = trainPersonsNames
Remove(trainPersonsNames
Length
)
}
Response
Redirect(
add
aspx?trainPersonsId=
+ trainPersonsId +
&&trainPersonsNames=
+ trainPersonsNames)
//JscriptMsg(
提交成功啦!
add
aspx?trainPersonsId=
+ trainPersonsId +
&&trainPersonsNames=
+ trainPersonsNames
Success
)
//JscriptMsg(
審核通過成功啦!
Utils
CombUrlTxt(
list
aspx
channel_id={
}&keywords={
}&property={
}
// this
channel_id
ToString()
this
keywords
this
property)
Success
)
}
From:http://tw.wingwit.com/Article/program/net/201311/13738.html