我的 asp.net 页面上有一个 Datalist,ImageButton
其中<Item Template>
. 单击an 时ImageButton
,我使用ItemCommand
事件设置数据项的边框:
protected void dlProducts_ItemCommand(object source, DataListCommandEventArgs e)
{
e.Item.BorderColor = System.Drawing.ColorTranslator.FromHtml("#ff5800");
e.Item.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffeee5");
}
这很好用,但是当回发发生时边框会消失。我尝试在页面加载事件中绑定我的数据列表,如下所示:
if (!Page.IsPostBack)
{
dlProducts.DataSource = ObjectDataSource4;
dlProducts.DataKeyField = "Product_ID";
dlProducts.DataBind();
}
但是回发后边界消失了。是什么赋予了?
这是数据列表标记:
<asp:DataList ID="dlProducts" runat="server" CellPadding="5" CellSpacing="5"
OnItemCommand="dlProducts_ItemCommand"
RepeatColumns="4" RepeatDirection="Horizontal"
ondatabinding="dlProducts_DataBinding"
onitemdatabound="dlProducts_ItemDataBound" >
<ItemTemplate>
<asp:ImageButton ID="img" ImageAlign="Middle" runat="server"
ImageUrl='<%# "~/uploads/profile/" + DataBinder.Eval(Container.DataItem,"ProfileImageName").ToString() %>'
onclick="img_Click" />
</ItemTemplate>
</asp:DataList><asp:ObjectDataSource ID="ObjectDataSource4" runat="server" SelectMethod="GetAllCompetitorProducts"
TypeName="DalProduct" OldValuesParameterFormatString="original_{0}">
<SelectParameters>
<asp:SessionParameter Name="producttype_id" SessionField="ProductType_id" Type="Int32" DefaultValue="13" />
<asp:SessionParameter DefaultValue="2009" Name="Year" SessionField="Year" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>