當我試圖找到控制n個數據列表,我下面提到查找控制在Datalist中
Error(Object reference not set to an instance of an object.
我不知道
protected void dlCategory_ItemDataBound(object sender, DataListItemEventArgs e)
{
Label Lb = (Label)e.Item.FindControl("LblCat");
Lb.ForeColor = System.Drawing.Color.Red;
}
<Datalist>
<asp:DataList ID="dlSubCategory" runat="server"
DataSource='<%# GetSubCategory(Convert.ToString(Eval("Category_ID")))%>'
onitemcreated="dlSubCategory_ItemCreated"
onitemdatabound="dlSubCategory_ItemDataBound">
<EditItemStyle ForeColor="#CC3300" />
<SelectedItemStyle ForeColor="#CC3300" />
<ItemTemplate>
<div class="buttn_div_sub">
<div class="lm40 tm2 buttn_txt">
<a href='<%# Convert.ToString(Eval("ProductCategory_Id")).Insert(0,"ListView.aspx?ProductCategory_Id=") %>'
class="buttn_txt">
<asp:Label ID="Label1" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"Name") %>'></asp:Label>
</a>
</div>
</div>
</ItemTemplate>
</asp:DataList>
</ItemTemplate>
@Kareem:請格式化你的代碼。 http://meta.stackexchange.com/questions/22186/how-do-i-get-my-code-formatted-in-stackoverflow – 2010-04-01 12:23:47