Good morning,
I've a problem with a dropdownlist located inside any row of a datalist,
I fill both datalist and dropdownlist at runtime, the problem is with the
dropdownlist infact using the event OnItemDataBound I can fill it but it is
impossible for me to load the right selectedItem.Va lue , infact looking at
the html page produced by the server I've this strange code :
<select name="MyDataCam pi:_ctl1:ComboT ipoPartita"
id="MyDataCampi __ctl1_ComboTip oPartita">
<option selected="selec ted" value="1">Calce tto</option>
<option value="2">Calci otto</option>
<option value="3">Calci o</option>
and also
<option selected="selec ted" value="3">Calce tto</option>
<option value="2">Calci otto</option>
<option value="3">Calci o</option>
while I expect something like selected = "true" and the value of Calcetto
always "1".
If you want please take a look at the code that produce this strange
behaviour and try to help me,
with this I create the dataset for the combobox and put it in the Session:
void CreateDataViewC omboBoxes() {
OleDbconn = new OleDbConnection (sConnessioneDb );
OleDbconn.Open( );
DataSet dsComboBoxes = new DataSet();
dsComboBoxes.Ta bles.Add("TipoP artita");
OleDbDataAdapte r daTipoPartita = new OleDbDataAdapte r("SELECT
IDTipoPartita, DescrizioneTipo Partita from TipoPartita " ,OleDbconn);
daTipoPartita.F ill(dsComboBoxe s,"TipoPartita" );
Session["dsComboBox es"] = dsComboBoxes;
dsComboBoxes.Di spose();
OleDbconn.Close ();
}
and with this I fill the dropdownlist:
void BindComboes(Obj ect sender, DataListItemEve ntArgs e)
{
if (e.Item.ItemTyp e == ListItemType.It em ||
e.Item.ItemType == ListItemType.Al ternatingItem ||
e.Item.ItemType == ListItemType.Ed itItem
)
{
DataSet dsComboBoxes = (DataSet)Sessio n["dsComboBox es"] ;
String sIDTipoPartita =
((HtmlInputHidd en)e.Item.FindC ontrol("HiddenI DTipoPartita")) .Value;
DropDownList ComboTipoPartit a =
(DropDownList)e .Item.FindContr ol("ComboTipoPa rtita");
ComboTipoPartit a.DataValueFiel d = "IDTipoPartita" ;
ComboTipoPartit a.DataTextField = "DescrizioneTip oPartita";
ComboTipoPartit a.DataSource =
dsComboBoxes.Ta bles["TipoPartit a"];
ComboTipoPartit a.DataBind();
ComboTipoPartit a.SelectedItem. Value = sIDTipoPartita;
dsComboBoxes.Di spose();
}
}
and this is the declaration of the dataset :
<ASP:DataList id="MyDataCampi " runat="server" ...
OnItemDataBound ="BindComboe s" >
<ItemTemplate >
<tr style="backgrou nd-color:CCFF99">
<td>
<input id="HiddenIDTip oPartita" type="hidden" value='<%#
DataBinder.Eval (Container.Data Item, "IDTipoPartita" ) %>' runat="server" />
<asp:DropDownLi st id="ComboTipoPa rtita" Enabled="true"
runat="server"> </asp:DropDownLis t>
</td>
</tr>
</ItemTemplate>
If you have any suggest I'll be happy of this,
many thanks ...
Antonio D'Ottavio
www.etantonio.it/en