gridview 放置在转发器中,它在 itemdata 绑定上显示错误
代码,
<asp:Repeater ID="rptSearchResult" runat="server"
OnItemDataBound="rptSearchResult_ItemDataBound">
<HeaderTemplate>
<table border="0">
<tr>
<td> Cost Page</td>
<td> Cost Page Description</td>
<td> Vendor Name</td>
<td> Bill Type</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td> <%# Eval("CostPage")%></td>
<td><%# Eval("CostPageDescription")%> </td>
<td> <%# Eval("VendorName")%> </td>
<td><%# Eval("BillType")%> </td>
</tr>
<tr>
<td>
<asp:GridView ID="gvDetails" runat="server" >
<Columns>
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ItemId" HeaderText="Item ID"/>
<asp:BoundField DataField="ItemDescription" HeaderText="Item Description"/>
<asp:BoundField DataField="BrandCode" HeaderText="Brand Code"/>
</Columns>
</asp:GridView> </td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
在 .cs 文件中,
protected void rptSearchResult_ItemDataBound(
object sender, RepeaterItemEventArgs e)
{
GridView gd = (GridView)e.Item.FindControl("gvDetails");
details e1 = new details();
e1.itemid= 1;
e1.itemdesc = "item1";
e1.brandcode = "BBB";
List<details> employees = new List<details>();
employees.Add(e1);
gd.DataSource = employees;
gd.DataBind();
}