473,406 Members | 2,439 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Problem assigning selectedItem.Value to a dropdownlist filled with OnItemDataBound

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"
id="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);
OleDbconn.Open();
DataSet dsComboBoxes = new DataSet();
dsComboBoxes.Tables.Add("TipoPartita");
OleDbDataAdapter daTipoPartita = new OleDbDataAdapter("SELECT
IDTipoPartita, DescrizioneTipoPartita from TipoPartita " ,OleDbconn);
daTipoPartita.Fill(dsComboBoxes,"TipoPartita");
Session["dsComboBoxes"] = dsComboBoxes;
dsComboBoxes.Dispose();
OleDbconn.Close();
}

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 =
((HtmlInputHidden)e.Item.FindControl("HiddenIDTipo Partita")).Value;
DropDownList ComboTipoPartita =
(DropDownList)e.Item.FindControl("ComboTipoPartita ");
ComboTipoPartita.DataValueField = "IDTipoPartita";
ComboTipoPartita.DataTextField = "DescrizioneTipoPartita";
ComboTipoPartita.DataSource =
dsComboBoxes.Tables["TipoPartita"];
ComboTipoPartita.DataBind();
ComboTipoPartita.SelectedItem.Value = sIDTipoPartita;
dsComboBoxes.Dispose();
}
}
and this is the declaration of the dataset :

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

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

Antonio D'Ottavio
www.etantonio.it/en


Sep 19 '05 #1
1 1957
Yes you're right and solved my problem,
many thanks

Antonio D'ottavio
www.etantonio/en


"Antonio D'Ottavio" <po********@etantonio.it> ha scritto nel messaggio
news:u7*************@TK2MSFTNGP12.phx.gbl...
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"
id="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);
OleDbconn.Open();
DataSet dsComboBoxes = new DataSet();
dsComboBoxes.Tables.Add("TipoPartita");
OleDbDataAdapter daTipoPartita = new OleDbDataAdapter("SELECT
IDTipoPartita, DescrizioneTipoPartita from TipoPartita " ,OleDbconn);
daTipoPartita.Fill(dsComboBoxes,"TipoPartita");
Session["dsComboBoxes"] = dsComboBoxes;
dsComboBoxes.Dispose();
OleDbconn.Close();
}

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 =
((HtmlInputHidden)e.Item.FindControl("HiddenIDTipo Partita")).Value;
DropDownList ComboTipoPartita =
(DropDownList)e.Item.FindControl("ComboTipoPartita ");
ComboTipoPartita.DataValueField = "IDTipoPartita";
ComboTipoPartita.DataTextField = "DescrizioneTipoPartita";
ComboTipoPartita.DataSource =
dsComboBoxes.Tables["TipoPartita"];
ComboTipoPartita.DataBind();
ComboTipoPartita.SelectedItem.Value = sIDTipoPartita;
dsComboBoxes.Dispose();
}
}
and this is the declaration of the dataset :

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

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

Antonio D'Ottavio
www.etantonio.it/en

Sep 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: StillStuckOnJava | last post by:
I'm having a stupid problem with V.S./C#. I've created a class and two subclasses, and I want to instantiate either of hte subclasses after users make a selection. Then I want to use that class to...
0
by: huobazi | last post by:
I have many dropdownlist controls in my ascx (and use LoadControl in a aspx fiel) file,so i write a method "InitList(DropDownList list,string strsql,string TextField,string ValueField)" but when i...
7
by: Lastie | last post by:
Hi all, I’ve got a ‘dropdownlist’ web control and I can add ‘listitem’ no problem. I can also bind data from an SQL database fine. My problem is that I want to do both at the same...
5
by: Lasse Edsvik | last post by:
Hello I have a dropdown with 3 different values, and it prints out first value no matter how i change it...... private void Button1_Click(object sender, System.EventArgs e) { ...
7
by: androoo | last post by:
Hi I am learing how to use the grid in asp.net. Im trying to replace the button columns with nice friendly images. So : <asp:ButtonColumn Text="Delete"...
7
by: Girish | last post by:
OK.. phew. Playing with data grids for the past few days has been fun and a huge learning experience.. My problem. I have a requirement to display a gird with a gird. Within the embedded grid,...
2
by: Antonio D'Ottavio | last post by:
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...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
4
by: ^MisterJingo^ | last post by:
Hi all, I have a web page which has a single dropdownlist containing 3 items. Below the dropdownlist are two listboxes. Depending on the option selected from the dropdownlist, the left most...
1
by: aboalnodom | last post by:
hello guys, i hope any one will help in this i am designing a web application, the page i am workin on its the default.aspx it contains dropdownboxes the first 4 to choose the type and the...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.