如何在运行时设置DataList项目模板中保留的按钮的属性。 我需要对数据库按钮设置中的按钮进行设置。
<asp:DataList ID="btnDataList" runat="server" RepeatDirection="Horizontal"
RepeatColumns="4" onitemcreated="btnDataList_ItemCreated">
<ItemTemplate>
<asp:Button ID="itemBtn" runat="server" Text='<%# Bind("CategoryName") %>' CommandArgument='<%# Bind("CategoryID") %>' />
</ItemTemplate>
</asp:DataList>
我需要在fyl上为宽度,高度,字体颜色,类型等按钮应用setn
答案 0 :(得分:1)
void Item_Bound(Object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
// Retrieve the Button control in the current DataListItem.
Button btn = (Button)e.Item.FindControl("ItemBtn");
//Then set the buttons properties over here
}
}