(Scroll down to the end of the message to find a solution.)
Get the asp.net page that contains the DataList. Inside this datalist there is a template containing a drop-down list and each time the datalist is filled with an element, a ItemCreatedCommand is called. itemCreatedCommand is responsible for the databinding of the drop-down list.
I think the problem here is that I use ItemCreatedCommand to populate it - but the weird thing is that if I select the color "green", the page will be auto-retransmitted, and I will see that the drop-down list is still green, but when I try to use it's SelectedIndex, I always get 0 ...
protected void DataListProducts_ItemCreatedCommand(object
source, DataListItemEventArgs e)
var itemId = (String)DataListProducts.DataKeys[e.Item.ItemIndex];
var item = itemBLL.GetFullItem(itemId);
var DropDownListColor = (DropDownList)e.Item.FindControl("DropDownListColor");
DropDownListColor.DataSource = item.ColorList;
DropDownList.Color.Databind();
Label1.test = DropDownListColor.SelectedIndex.toString();
, ,
:)
,
i aspx-page, ,
if (showColors),
html-
,
.
EDIT:
SelectedIndexChange -
"" -
DataList? , ,
,
datalist this
...
?
, ;)
,
:)
:
ItemCommand, , ( datalistItem .
protected void DropDownListColor_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList dropDownListColor = (DropDownList)sender;
DataListItem dataListItem = (DataListItem)dropDownListColor.Parent;
var item = items[dataListItem.ItemIndex];
var color = item.ItemColor[dropDownListColor.SelectedIndex];
var LabelPrice = (Label)dataListItem.FindControl("LabelPrice");
LabelPrice.Text = color.Price;
}