您可以随时RowDataBound
使用GridView
<asp:GridView ID="gridView1" runat="server"
OnRowDataBound="gridView1_DataBound">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="myLabel" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
绑定数据时:
var myStrings = new List<string[]>
{
new [] { "hello", "bye"},
new [] { "1", "2"}
};
gridView1.DataSource = myStrings;
gridView1.DataBind();
RowDataBound
事件:
public void gvDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType != DataControlRowType.DataRow)
{
return;
}
var item = (string[]) e.Row.DataItem;
Label myLabel = e.Row.FindControl("myLabel") as Label;
myLabel.Text = item[0];
}