468,247 Members | 1,335 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,247 developers. It's quick & easy.

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

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
Nov 22 '05 #1
2 1708
As the error suggests, set the DataSource in the run-time in the datalist
ItemDataBound event.

Eliyahu

"Antonio D'Ottavio" <po********@etantonio.it> wrote in message
news:ew*************@tk2msftngp13.phx.gbl...
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

Nov 22 '05 #2
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" <re*************@monarchmed.com> ha scritto nel messaggio
news:eu**************@tk2msftngp13.phx.gbl... As the error suggests, set the DataSource in the run-time in the datalist
ItemDataBound event.

Eliyahu

"Antonio D'Ottavio" <po********@etantonio.it> wrote in message
news:ew*************@tk2msftngp13.phx.gbl...
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


Nov 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Ashish Sharma | last post: by
reply views Thread by Ashish Sharma | last post: by
2 posts views Thread by Shiju Poyilil | last post: by
1 post views Thread by Joe Blanchard via .NET 247 | last post: by
reply views Thread by kermitthefrogpy | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.