您的位置:首页 > 其它

GridView中嵌套Repeater方法

2009-01-20 09:50 288 查看
前台代码如下:
<asp:GridView ID="GridView2" runat="server" AllowPaging="True" OnPageIndexChanging="GridView2_PageIndexChanging" PageSize="5" AutoGenerateColumns="False" OnRowDataBound="GridView2_RowDataBound" Width="100%" CellPadding="0" ForeColor="#333333" GridLines="None" HorizontalAlign="Center">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<table border="0" cellpadding="0" cellspacing="1" width=100% style="background-color: #006699; border-right-style: none; border-left-style: none;" mce_style="background-color: #006699; border-right-style: none; border-left-style: none;">
<tr><td>
<table border="0" cellpadding="0" cellspacing="0" class="listtable">
<tr><td style="font-weight: bold; color: white; text-align: left;" mce_style="font-weight: bold; color: white; text-align: left;">    <%# Eval("Bug_title")%></td></tr>
<tr>
<td bgcolor="#FFFFFF" style="padding:10px; text-align: left;" mce_style="padding:10px; text-align: left;"><%# Eval("BUG_Content")%>
<%--嵌套一个Repeater5--%>
<asp:Label ID="lbl_IDD" runat="server" Text='<%# Eval("bug_ID") %>' Visible="False"></asp:Label>
<asp:Repeater ID="Repeater5" runat="server">
<ItemTemplate>
<%-- <hr width="100%" size="1" color="#CCCCCC">--%>
<fieldset><legend>
<strong><%# BR_Name(Eval("BR_user_id"))%>回复:</strong></legend><span class="Reply"><%# Eval("BR_content")%></span>
<div style="text-align: right;" mce_style="text-align: right;"><%# Eval("BR_cate")%>
<%# string.Format("{0:yyyy}-{0:MM}-{0:dd}", Eval("BR_adddate"))%>
</div>
</fieldset>
</ItemTemplate>
</asp:Repeater>
<%--end--%>
</td>
</tr>
<tr>
<td bgcolor="#FFFFFF" style="padding:4px; border-top: white thin solid;" mce_style="padding:4px; border-top: white thin solid;">
<ul class="bottomUl">
<li style="background:url(../images/1_r12_c14.jpg) no-repeat; width: 100px; position: static;">:<%# string.Format("{0:yyyy}-{0:MM}-{0:dd} {0:HH}:{0:mm}", Eval("Bug_adddate"))%></li>
<li style="background:url(../images/1_r12_c15.jpg) no-repeat; width: 80px; position: static;">:<%# Software_Name(Eval("Bug_sw_ID"))%></li>
<li style="background:url(../images/1_r12_c15.jpg) no-repeat; width: 80px; position: static;">:<%# Software_edition(Eval("Bug_Pro_ID"))%></li>
<li style="background:url(../images/1_r12_c16.jpg) no-repeat;" mce_style="background:url(images/1_r12_c16.jpg) no-repeat;">:<%# Eval("Bug_grade")%></li>
<li style="background:url(../images/1_r12_c16.jpg) no-repeat;" mce_style="background:url(images/1_r12_c16.jpg) no-repeat;">:<%# Eval("Bug_ok")%></li></ul>

</tr>
</table>
</td></tr></table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

后台代码如下:
private void BindGridView2()
{
sqlStr2 = "select * from bug where bug_pro_id='" + Request.QueryString["id"] + "' order by bug_adddate desc";

SqlDataAdapter myCommand = new SqlDataAdapter(sqlStr2, conn);
DataSet ds = new DataSet();
myCommand.Fill(ds, "Authors");
GridView2.DataSource = ds.Tables["Authors"].DefaultView;
GridView2.DataBind();

}
protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.GridView2.PageIndex = e.NewPageIndex;
BindGridView2();
}
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Repeater Repeater5_CS = null;
Label PD_IDD_CS = new Label();
Repeater5_CS = (Repeater)e.Row.FindControl("Repeater5");
if (Repeater5_CS != null)
{
PD_IDD_CS = (Label)e.Row.FindControl("lbl_IDD");
if (PD_IDD_CS != null)
{
string PD_IDD = PD_IDD_CS.Text.ToString();
SqlDataAdapter sda = new SqlDataAdapter("select * from BugReply where BR_Bug_ID='" + PD_IDD + "'", conn);
DataSet ds = new DataSet();
sda.Fill(ds, "table");
Repeater5_CS.DataSource = ds.Tables["table"].DefaultView;
Repeater5_CS.DataBind();
}
}
}
}


注:区别如下

GridView中嵌套Repeater方法:protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e){}

Repeater中嵌套Repeater方法:protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e){}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: