请任何人都可以查看我的代码并告诉我 itemCommand 在按钮单击时没有被触发的原因是什么。
<div class="">
<asp:Repeater ID="Repeater" runat="server" OnItemDataBound="Repeater_ItemDataBound" OnItemCommand="Repeater_ItemCommand">
<HeaderTemplate>
<div id="header" style="background-color:red">
</div>
</HeaderTemplate>
<ItemTemplate>
<div class="bms-car-item">
<div >
<image style="width:80px;height:60px" src="http://img2.netcarshow.com/Volkswagen-Golf_R32_2005_800x600_wallpaper_01.jpg"></image>
</div>
<div>
Car Type : <b> <%# DataBinder.Eval(Container.DataItem, "VehicleGroup") %> class or Similar </b>
</div>
<div>
Car Group: <b> <%# DataBinder.Eval(Container.DataItem, "SupplierGroup") %></b>
</div>
<div>
Properties:
<cp:CarProperties ID="CarPropertiesControl" runat="server" />
</div>
<div>
Price Before Voucher: <%# DataBinder.Eval(Container.DataItem, "PriceCust.Price") %> <%# DataBinder.Eval(Container.DataItem, "PriceCust.Currency") %>
</div>
<div>
Price per Rent:<b class="PricePlaceHolder"> <%# DataBinder.Eval(Container.DataItem, "PriceCust.Price") %> <%# DataBinder.Eval(Container.DataItem, "PriceCust.Currency") %></b>
</div>
<div>
<a href="#" onclick="return ShowTerms()" >Additional Info</a>
<a href="#">Options Included in Price</a>
</div>
<asp:HiddenField ID="Selected" runat="server" value='<%# DataBinder.Eval(Container.DataItem, "VehicleModelCode") %>'></asp:HiddenField>
</div>
<div> <asp:Button Text="Select" ID="SelectButtonNext" CommandName="Get" runat="server" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "VehicleModelCode") %>' /></div>
</ItemTemplate>
</asp:Repeater>
</div>
以及类后面的相关代码
protected void Page_Load(object sender, EventArgs e)
{
var state = SessionManager.GetReservationState();
//Load All Car Groups
if (!Page.IsPostBack)
{
LoadCurrencies();
LoadModels(state);
}
else
{
Repeater.DataBind();
}
}
private void LoadModels(BmsReservationHelper state)
{
if (state != null)
{
var carModels = BmsFascade.BmsFascade.GetCarsAndPrices(state.PickUpLocationCode.Trim(), state.PickUpTime.ToString(), state.ReturnTime.ToString(), "", "", "", "");
// TODO: Check what to do if BMS returning 0 cars avaliable ...
this.Repeater.DataSource = carModels.VehicleModels;
this.Repeater.DataBind();
var groups = carModels.VehicleModels.GroupBy(m => m.SupplierGroup).Select(m => m.FirstOrDefault());
foreach (var g in groups)
{
this.CarGroupsFilter.Items.Add(new ListItem(g.SupplierGroup, g.SupplierGroup));
}
}
}
private void LoadCurrencies()
{
this.CurrencyList.Items.Clear();
// Load All Currencies
var list = BmsFascade.BmsFascade.GetCurrencies();
foreach (var currencyPipe in list.ReturnValues)
{
string[] values = currencyPipe.Split('|');
this.CurrencyList.Items.Add(new ListItem(values[1], values[0]));
}
}
protected void Repeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
// Bind Car properties strip to the repeater control
if (e.Item.DataItem != null)
{
var model = e.Item.DataItem as BMSEntities.VehicleModelsBatchVehicleModel;
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
// Trying to rebing command properties here ... no luck :-(
Button myButton = (Button)e.Item.FindControl("SelectButton");
myButton.CommandName = "Get";
myButton.CommandArgument = model.VehicleGroup;
}
BMS_BmsCarProperties_BmsCarProperties carProps = e.Item.FindControl("CarPropertiesControl") as BMS_BmsCarProperties_BmsCarProperties;
if (carProps != null)
{
// model.VehicleModelInfo.
carProps.LoadDataInfo(model);
}
}
}
protected void Repeater_ItemCommand(object source, RepeaterCommandEventArgs e)
{
var x = e.CommandArgument;
Response.Write("fdsljknalsjndflkjasndflkjansdlkfjnasldkjnf");
}