1,工作中遇到这样一个需求,页面上要把所有的user加载出来,同时每个user后面紧跟着要把user的任务加载出来!我的处理方法是用repeater来加载所有的user,同时在repeater里面嵌套一个gridview,将每个user的任务展示出来!代码如下
前台代码:
<asp:repeater id=repeater1 runat=server
onitemdatabound=repeater1_itemdatabound>
<headertemplate>
<table border=0 cellspacing=0 cellpadding=0 width=100%>
<tr>
</headertemplate>
<itemtemplate>
<td class=list_table_in>
<span class=leadertitle>高管:<a href='/leaderschedule/_layouts/ls/leaderdetail.aspx?loginname=<%#eval(loginname) %>'><%#eval(username) %></a></span><asp:gridview id=gv_inrep runat=server autogeneratecolumns=false allowsorting=true
onrowcreated=gv_donelist_rowcreated onsorting=gv_donelist_sorting allowpaging=true
cssclass=tasklisttbl width=100% onrowdatabound=gv_donelist_rowdatabound
enablemodelvalidation=true>
<alternatingrowstyle backcolor=#fdfeff />
<headerstyle horizontalalign=center forecolor=black height=20 />
<rowstyle horizontalalign=center height=26px />
<columns>
<asp:boundfield headertext=日期 itemstyle-cssclass=custom datafield=date sortexpression=date>
<itemstyle width=15% />
</asp:boundfield>
<asp:boundfield headertext=时间 datafield=time sortexpression=time>
<itemstyle width=11% />
</asp:boundfield>
<asp:boundfield headertext=工作安排 datafield=workplan sortexpression=workplan>
<itemstyle width=11% />
</asp:boundfield>
<asp:boundfield headertext=地点 datafield=place sortexpression=place>
<itemstyle width=11% />
</asp:boundfield>
</columns>
<pagertemplate>
</pagertemplate>
</asp:gridview>
</td>
<asp:literal id=literal1 runat=server text='<%#eval(flag) %>'></asp:literal>
</itemtemplate>
<footertemplate>
</tr></table>
</footertemplate>
</asp:repeater>
后台代码:
protected void repeater1_itemdatabound(object sender, repeateritemeventargs e)
{
try
{
if (e.item.itemtype == listitemtype.item || e.item.itemtype == listitemtype.alternatingitem)
{
gridview gv = e.item.findcontrol(gv_inrep) as gridview;//找到里层的repeater对象
leader rowv = (leader)e.item.dataitem;//找到分类repeater关联的数据项
string typeid = rowv.loginname; //获取填充子类的id
setsorting();
gv.datasource = pointdatasource(typeid);
gv.databind();
}
}
catch (exception ex)
{
syslog syslog = new syslog();
syslog.listname = constdata.listname_pcitc_ls_schedule;
syslog.ltype = repeater的item绑定事件异常;
syslog.workflowname = 领导日程管理系统;
syslog.location = repeater绑定数据:otherschedule.aspx;
syslog.message = 页面信息加载异常: + ex.message;
syslog.datasource = 0;
logprovider.addauditrecordtosource(syslog);
}
}
更多信息请查看IT技术专栏