0
我在我的asp.net頁面上有一個Datalist,在<Item Template>
中有一個ImageButton
。當點擊ImageButton
,我用的是ItemCommand
事件來設置數據項的邊框:Datalist回發問題
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>
您可以發佈您的數據列表標記 – Sunny