473,387 Members | 1,899 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,387 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 1954
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.