How to insert a dropdownlist sourced by a dB inside a datalist row

Discussion in 'ASP .Net Web Controls' started by Antonio D'Ottavio, Sep 12, 2005.

  1. Good Morning,
    In my web page I've a datalist that is sourced by a database,
    the problem is that I want that one of the column of the datalist contain a
    dropdownbox
    that also is sourced by a table in the database.

    <asp:DropDownList id="ComboTipoPartita" runat="server"
    DataValueField="IDTipoPartita"
    DataTextField="DescrizioneTipoPartita"
    DataSource="<% BindComboTipoPartita() %>"
    ></asp:DropDownList>


    this seems impossible in aspx c# , the error tells :

    " 'DataSource' property could be set just at runtime and cannot be declared
    "

    I'm interested to solve my problem of insert a dropdownlist powered by a db
    inside a row of the datalist,
    how I can achieve this ??

    Many thanks.

    Eng. Antonio D'Ottavio
    www.etantonio.it/en
     
    Antonio D'Ottavio, Sep 12, 2005
    #1
    1. Advertising

  2. As the error suggests, set the DataSource in the run-time in the datalist
    ItemDataBound event.

    Eliyahu

    "Antonio D'Ottavio" <> wrote in message
    news:...
    > Good Morning,
    > In my web page I've a datalist that is sourced by a database,
    > the problem is that I want that one of the column of the datalist contain

    a
    > dropdownbox
    > that also is sourced by a table in the database.
    >
    > <asp:DropDownList id="ComboTipoPartita" runat="server"
    > DataValueField="IDTipoPartita"
    > DataTextField="DescrizioneTipoPartita"
    > DataSource="<% BindComboTipoPartita() %>"
    > ></asp:DropDownList>

    >
    > this seems impossible in aspx c# , the error tells :
    >
    > " 'DataSource' property could be set just at runtime and cannot be

    declared
    > "
    >
    > I'm interested to solve my problem of insert a dropdownlist powered by a

    db
    > inside a row of the datalist,
    > how I can achieve this ??
    >
    > Many thanks.
    >
    > Eng. Antonio D'Ottavio
    > www.etantonio.it/en
    >
    >
     
    Eliyahu Goldin, Sep 12, 2005
    #2
    1. Advertising

  3. Thanks for your suggestion but I still have some problem
    this is the error

    System.NullReferenceException: Reference to an Object not setted on a
    object instance

    I have on the row numer 5 of the following function :

    void BindComboTipoPartita(Object sender, DataListItemEventArgs e)
    {
    dsCampi.Tables.Add("TipoPartita");
    OleDbDataAdapter daTipoPartita = new OleDbDataAdapter("SELECT
    IDTipoPartita, DescrizioneTipoPartita from TipoPartita" ,OleDbconn);
    daTipoPartita.Fill(dsCampi,"TipoPartita");
    DropDownList ComboTipoPartita_DDL =
    (DropDownList)e.Item.FindControl("ComboTipoPartita");
    ComboTipoPartita_DDL.DataSource=dsCampi.Tables["TipoPartita"];
    ComboTipoPartita_DDL.DataBind();
    }

    and this is the datalist defined in the way you suggest :

    <ASP:DataList id="MyDataCampi" runat="server" HorizontalAlign="Center"
    RepeatDirection="Horizontal" RepeatColumns="1"
    OnEditCommand="Edit_Command" OnUpdateCommand="Update_Command"
    OnDeleteCommand="Delete_Command"
    OnCancelCommand="Cancel_Command" OnItemDataBound="BindComboTipoPartita"
    >

    <HeaderTemplate>
    <table width="100%" style="font: 8pt verdana">
    </HeaderTemplate>

    <ItemTemplate>
    <tr style="background-color:CCFF99">
    <td>
    <asp:DropDownList id="ComboTipoPartita" runat="server"
    DataValueField="IDTipoPartita"
    DataTextField="DescrizioneTipoPartita"
    ></asp:DropDownList>

    </td>
    </tr>
    </ItemTemplate>

    <FooterTemplate>
    </table>
    </FooterTemplate>
    </ASP:DataList>


    Have you any idea to solve the problem ???
    Thanks ....

    Antonio D'Ottavio
    www.etantonio.it/en




    "Eliyahu Goldin" <> ha scritto nel messaggio
    news:...
    > As the error suggests, set the DataSource in the run-time in the datalist
    > ItemDataBound event.
    >
    > Eliyahu
    >
    > "Antonio D'Ottavio" <> wrote in message
    > news:...
    > > Good Morning,
    > > In my web page I've a datalist that is sourced by a database,
    > > the problem is that I want that one of the column of the datalist

    contain
    > a
    > > dropdownbox
    > > that also is sourced by a table in the database.
    > >
    > > <asp:DropDownList id="ComboTipoPartita" runat="server"
    > > DataValueField="IDTipoPartita"
    > > DataTextField="DescrizioneTipoPartita"
    > > DataSource="<% BindComboTipoPartita() %>"
    > > ></asp:DropDownList>

    > >
    > > this seems impossible in aspx c# , the error tells :
    > >
    > > " 'DataSource' property could be set just at runtime and cannot be

    > declared
    > > "
    > >
    > > I'm interested to solve my problem of insert a dropdownlist powered by a

    > db
    > > inside a row of the datalist,
    > > how I can achieve this ??
    > >
    > > Many thanks.
    > >
    > > Eng. Antonio D'Ottavio
    > > www.etantonio.it/en
    > >
    > >

    >
    >
     
    Antonio D'Ottavio, Sep 13, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Antonio D'Ottavio
    Replies:
    0
    Views:
    430
    Antonio D'Ottavio
    Sep 12, 2005
  2. Antonio D'Ottavio
    Replies:
    1
    Views:
    1,226
    =?Utf-8?B?U2FjaGluIFNha2k=?=
    Sep 16, 2005
  3. Antonio D'Ottavio
    Replies:
    2
    Views:
    1,598
    Antonio D'Ottavio
    Sep 13, 2005
  4. H5N1
    Replies:
    0
    Views:
    2,725
  5. Antonio D'Ottavio

    How to ... Dropdownlist sourced by a DB inside a datalist ??

    Antonio D'Ottavio, Sep 16, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    117
    Antonio D'Ottavio
    Sep 16, 2005
Loading...

Share This Page