未完。。
前台代码:
<asp:Repeater ID="Repeater_Info" runat="server" OnItemDataBound="Repeater_Info_ItemDataBound">
//OnItemDataBound是绑定后台,使后台的代码和repeater绑定
<ItemTemplate>
<tr>
<td width="20" nowrap="nowrap">//nowrap:表单内容不换行
<strong>内容1</strong>
</td>
<td align="left" nowrap="nowrap">
<strong>内容2</strong>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Repeater ID="Content_List" runat="server">
<ItemTemplate>
<td nowrap="nowrap" runat="server" id="typeTd">//runat="server",服务器控件的使用,可以在后台调用id
</td>
<td>
<label for="<%#Eval("ContentID") %>">//绑定后台数据
<%#Eval("Content") %>
</label>//点击label上显示的后台的Content的内容,可以选中ContentID绑定的内容
</td>
</ItemTemplate>
</asp:Repeater>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
后台代码:
protected void Repeater_Info_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
//判断里层repeater处于外层repeater的哪个位置( AlternatingItemTemplate,FooterTemplate,HeaderTemplate,ItemTemplate,SeparatorTemplate)
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater rep = e.Item.FindControl("Content_List") as Repeater;//找到里层的repeater对象
rep.ItemDataBound += new RepeaterItemEventHandler(rep_ItemDataBound);
DataRowView rowv = (DataRowView)e.Item.DataItem;//找到分类Repeater关联的数据项
int typeid = Convert.ToInt32(rowv["QuestionID"]); //获取填充子类的id
//数据库的连接,数据的绑定
DataTable dt = dsInfo.Tables[0];
AQ.TypeID = (int)dt.Rows[0]["TypeID"];
rep.DataSource = dsInfo.Tables[0];//数据绑定
rep.DataBind();
}
}
void rep_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
//找到里层的td对象
HtmlTableCell td = e.Item.FindControl("typeTd") as HtmlTableCell;
DataRowView rowv = (DataRowView) e.Item.DataItem ;
if ((int)rowv["TypeID"] == 1)
{
td.InnerHtml = "<input type=\"radio\" id=\"" + rowv["ContentID"].ToString() + "\" name=\"" + rowv["QuestionID"].ToString() + "\" value=\"" + rowv["ContentID"].ToString() + "\"/>";
}
else if ((int)rowv["TypeID"] == 2)
{
td.InnerHtml = "<input type=\"checkbox\" id=\"" + rowv["ContentID"].ToString() + "\" name=\"" + rowv["QuestionID"].ToString() + "\" value=\"" + rowv["ContentID"].ToString() + "\"/>";
}
else
{
td.InnerHtml = "<input type=\"text\" id=\"" + rowv["ContentID"].ToString() + "\" name=\"" + rowv["QuestionID"].ToString() + "\" value=\"" + rowv["ContentID"].ToString() + "\"/>";
}
}
}