Problem assigning selectedItem.Value to a dropdownlist filled with OnItemDataBound

Discussion in 'ASP .Net' started by Antonio D'Ottavio, Sep 19, 2005.

  1. 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.Value , infact looking at
    the html page produced by the server I've this strange code :

    <select name="MyDataCampi:_ctl1:ComboTipoPartita"
    <option selected="selected" value="1">Calcetto</option>
    <option value="2">Calciotto</option>
    <option value="3">Calcio</option>

    and also

    <option selected="selected" value="3">Calcetto</option>
    <option value="2">Calciotto</option>
    <option value="3">Calcio</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 CreateDataViewComboBoxes() {
    OleDbconn = new OleDbConnection(sConnessioneDb);
    DataSet dsComboBoxes = new DataSet();
    OleDbDataAdapter daTipoPartita = new OleDbDataAdapter("SELECT
    IDTipoPartita, DescrizioneTipoPartita from TipoPartita " ,OleDbconn);
    Session["dsComboBoxes"] = dsComboBoxes;

    and with this I fill the dropdownlist:

    void BindComboes(Object sender, DataListItemEventArgs e)
    if (e.Item.ItemType == ListItemType.Item ||
    e.Item.ItemType == ListItemType.AlternatingItem ||
    e.Item.ItemType == ListItemType.EditItem
    DataSet dsComboBoxes = (DataSet)Session["dsComboBoxes"] ;
    String sIDTipoPartita =
    DropDownList ComboTipoPartita =
    ComboTipoPartita.DataValueField = "IDTipoPartita";
    ComboTipoPartita.DataTextField = "DescrizioneTipoPartita";
    ComboTipoPartita.DataSource =
    ComboTipoPartita.SelectedItem.Value = sIDTipoPartita;

    and this is the declaration of the dataset :

    <ASP:DataList id="MyDataCampi" runat="server" ...
    OnItemDataBound="BindComboes" >
    <tr style="background-color:CCFF99">
    <input id="HiddenIDTipoPartita" type="hidden" value='<%#
    DataBinder.Eval(Container.DataItem, "IDTipoPartita") %>' runat="server" />
    <asp:DropDownList id="ComboTipoPartita" Enabled="true"

    If you have any suggest I'll be happy of this,
    many thanks ...

    Antonio D'Ottavio
    Antonio D'Ottavio, Sep 19, 2005
    1. Advertisements

  2. Yes you're right and solved my problem,
    many thanks

    Antonio D'ottavio

    Antonio D'Ottavio, Sep 19, 2005
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.