在ItemDataBound中设置对象值的问题,大家帮我看看
我在Repeater中,设置了一标签, <asp:Label id= "mark " runat= "server "> </asp:Label>
我在Repeater的ItemDataBound事件中设置mark的TEXT值,发生错误:
未将对象引用设置到对象的实例 代码是:
private void note_list_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
Label strlabel = new Label();
strlabel = (Label)e.Item.FindControl( "mark ");
strlabel.Text= "aaaaaaa ";//这行发生了错误
}
------解决方案--------------------简单的说可以这样干:
Repeater.DataSource = dt;
Repeater.DataBind();
for (int i = 0; i < Repeater.Items.Count; i++)
{
Label strlabel =(Label)e.Item.FindControl( "mark ");
strlabel.Text= "aaaaaaa ";
}