473,569 Members | 2,402 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem assigning selectedItem.Va lue 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.Va lue , infact looking at
the html page produced by the server I've this strange code :

<select name="MyDataCam pi:_ctl1:ComboT ipoPartita"
id="MyDataCampi __ctl1_ComboTip oPartita">
<option selected="selec ted" value="1">Calce tto</option>
<option value="2">Calci otto</option>
<option value="3">Calci o</option>

and also

<option selected="selec ted" value="3">Calce tto</option>
<option value="2">Calci otto</option>
<option value="3">Calci o</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 CreateDataViewC omboBoxes() {
OleDbconn = new OleDbConnection (sConnessioneDb );
OleDbconn.Open( );
DataSet dsComboBoxes = new DataSet();
dsComboBoxes.Ta bles.Add("TipoP artita");
OleDbDataAdapte r daTipoPartita = new OleDbDataAdapte r("SELECT
IDTipoPartita, DescrizioneTipo Partita from TipoPartita " ,OleDbconn);
daTipoPartita.F ill(dsComboBoxe s,"TipoPartita" );
Session["dsComboBox es"] = dsComboBoxes;
dsComboBoxes.Di spose();
OleDbconn.Close ();
}

and with this I fill the dropdownlist:

void BindComboes(Obj ect sender, DataListItemEve ntArgs e)
{
if (e.Item.ItemTyp e == ListItemType.It em ||
e.Item.ItemType == ListItemType.Al ternatingItem ||
e.Item.ItemType == ListItemType.Ed itItem
)
{
DataSet dsComboBoxes = (DataSet)Sessio n["dsComboBox es"] ;
String sIDTipoPartita =
((HtmlInputHidd en)e.Item.FindC ontrol("HiddenI DTipoPartita")) .Value;
DropDownList ComboTipoPartit a =
(DropDownList)e .Item.FindContr ol("ComboTipoPa rtita");
ComboTipoPartit a.DataValueFiel d = "IDTipoPartita" ;
ComboTipoPartit a.DataTextField = "DescrizioneTip oPartita";
ComboTipoPartit a.DataSource =
dsComboBoxes.Ta bles["TipoPartit a"];
ComboTipoPartit a.DataBind();
ComboTipoPartit a.SelectedItem. Value = sIDTipoPartita;
dsComboBoxes.Di spose();
}
}
and this is the declaration of the dataset :

<ASP:DataList id="MyDataCampi " runat="server" ...
OnItemDataBound ="BindComboe s" >
<ItemTemplate >
<tr style="backgrou nd-color:CCFF99">
<td>
<input id="HiddenIDTip oPartita" type="hidden" value='<%#
DataBinder.Eval (Container.Data Item, "IDTipoPartita" ) %>' runat="server" />
<asp:DropDownLi st id="ComboTipoPa rtita" Enabled="true"
runat="server"> </asp:DropDownLis t>
</td>
</tr>
</ItemTemplate>

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

Antonio D'Ottavio
www.etantonio.it/en


Nov 19 '05 #1
2 2173
I think i see the problemo

the line:
ComboTipoPartit a.SelectedItem. Value = sIDTipoPartita;

in the "CreateDataView ComboBoxes()" method should read:
ComboTipoPartit a.Item.FindByVa lue(sIDTipoPart ita).Selected = true;

Because the way your setting it, its actually resetting the value of the
selected item (the first in the list)

Hope that helps

"Antonio D'Ottavio" <po********@eta ntonio.it> wrote in message
news:u7******** *****@TK2MSFTNG P12.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.Va lue , infact looking at
the html page produced by the server I've this strange code :

<select name="MyDataCam pi:_ctl1:ComboT ipoPartita"
id="MyDataCampi __ctl1_ComboTip oPartita">
<option selected="selec ted" value="1">Calce tto</option>
<option value="2">Calci otto</option>
<option value="3">Calci o</option>

and also

<option selected="selec ted" value="3">Calce tto</option>
<option value="2">Calci otto</option>
<option value="3">Calci o</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 CreateDataViewC omboBoxes() {
OleDbconn = new OleDbConnection (sConnessioneDb );
OleDbconn.Open( );
DataSet dsComboBoxes = new DataSet();
dsComboBoxes.Ta bles.Add("TipoP artita");
OleDbDataAdapte r daTipoPartita = new OleDbDataAdapte r("SELECT
IDTipoPartita, DescrizioneTipo Partita from TipoPartita " ,OleDbconn);
daTipoPartita.F ill(dsComboBoxe s,"TipoPartita" );
Session["dsComboBox es"] = dsComboBoxes;
dsComboBoxes.Di spose();
OleDbconn.Close ();
}

and with this I fill the dropdownlist:

void BindComboes(Obj ect sender, DataListItemEve ntArgs e)
{
if (e.Item.ItemTyp e == ListItemType.It em ||
e.Item.ItemType == ListItemType.Al ternatingItem ||
e.Item.ItemType == ListItemType.Ed itItem
)
{
DataSet dsComboBoxes = (DataSet)Sessio n["dsComboBox es"] ;
String sIDTipoPartita =
((HtmlInputHidd en)e.Item.FindC ontrol("HiddenI DTipoPartita")) .Value;
DropDownList ComboTipoPartit a =
(DropDownList)e .Item.FindContr ol("ComboTipoPa rtita");
ComboTipoPartit a.DataValueFiel d = "IDTipoPartita" ;
ComboTipoPartit a.DataTextField = "DescrizioneTip oPartita";
ComboTipoPartit a.DataSource =
dsComboBoxes.Ta bles["TipoPartit a"];
ComboTipoPartit a.DataBind();
ComboTipoPartit a.SelectedItem. Value = sIDTipoPartita;
dsComboBoxes.Di spose();
}
}
and this is the declaration of the dataset :

<ASP:DataList id="MyDataCampi " runat="server" ...
OnItemDataBound ="BindComboe s" >
<ItemTemplate >
<tr style="backgrou nd-color:CCFF99">
<td>
<input id="HiddenIDTip oPartita" type="hidden" value='<%#
DataBinder.Eval (Container.Data Item, "IDTipoPartita" ) %>' runat="server" />
<asp:DropDownLi st id="ComboTipoPa rtita" Enabled="true"
runat="server"> </asp:DropDownLis t>
</td>
</tr>
</ItemTemplate>

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

Antonio D'Ottavio
www.etantonio.it/en

Nov 19 '05 #2
Yes you're right and solved my problem,
many thanks

Antonio D'ottavio
www.etantonio/en


"Antonio D'Ottavio" <po********@eta ntonio.it> ha scritto nel messaggio
news:u7******** *****@TK2MSFTNG P12.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.Va lue , infact looking at
the html page produced by the server I've this strange code :

<select name="MyDataCam pi:_ctl1:ComboT ipoPartita"
id="MyDataCampi __ctl1_ComboTip oPartita">
<option selected="selec ted" value="1">Calce tto</option>
<option value="2">Calci otto</option>
<option value="3">Calci o</option>

and also

<option selected="selec ted" value="3">Calce tto</option>
<option value="2">Calci otto</option>
<option value="3">Calci o</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 CreateDataViewC omboBoxes() {
OleDbconn = new OleDbConnection (sConnessioneDb );
OleDbconn.Open( );
DataSet dsComboBoxes = new DataSet();
dsComboBoxes.Ta bles.Add("TipoP artita");
OleDbDataAdapte r daTipoPartita = new OleDbDataAdapte r("SELECT
IDTipoPartita, DescrizioneTipo Partita from TipoPartita " ,OleDbconn);
daTipoPartita.F ill(dsComboBoxe s,"TipoPartita" );
Session["dsComboBox es"] = dsComboBoxes;
dsComboBoxes.Di spose();
OleDbconn.Close ();
}

and with this I fill the dropdownlist:

void BindComboes(Obj ect sender, DataListItemEve ntArgs e)
{
if (e.Item.ItemTyp e == ListItemType.It em ||
e.Item.ItemType == ListItemType.Al ternatingItem ||
e.Item.ItemType == ListItemType.Ed itItem
)
{
DataSet dsComboBoxes = (DataSet)Sessio n["dsComboBox es"] ; String sIDTipoPartita =
((HtmlInputHidd en)e.Item.FindC ontrol("HiddenI DTipoPartita")) .Value;
DropDownList ComboTipoPartit a =
(DropDownList)e .Item.FindContr ol("ComboTipoPa rtita");
ComboTipoPartit a.DataValueFiel d = "IDTipoPartita" ;
ComboTipoPartit a.DataTextField = "DescrizioneTip oPartita";
ComboTipoPartit a.DataSource =
dsComboBoxes.Ta bles["TipoPartit a"];
ComboTipoPartit a.DataBind();
ComboTipoPartit a.SelectedItem. Value = sIDTipoPartita;
dsComboBoxes.Di spose();
}
}
and this is the declaration of the dataset :

<ASP:DataList id="MyDataCampi " runat="server" ...
OnItemDataBound ="BindComboe s" >
<ItemTemplate >
<tr style="backgrou nd-color:CCFF99">
<td>
<input id="HiddenIDTip oPartita" type="hidden" value='<%#
DataBinder.Eval (Container.Data Item, "IDTipoPartita" ) %>' runat="server" />
<asp:DropDownLi st id="ComboTipoPa rtita" Enabled="true"
runat="server"> </asp:DropDownLis t>
</td>
</tr>
</ItemTemplate>

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

Antonio D'Ottavio
www.etantonio.it/en

Nov 19 '05 #3

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

Similar topics

1
1980
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 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...
5
1256
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 modify its members as users make more selections. IT'S NOT WORKING DAMN IT! The following is my asp.net behind code for the web form, and then my...
0
1969
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 want to get the BigClassList.SelectedItem.Text and BigClassList.SelectedItem.Value in a button onclick method,btnSmallClassEdit_Click(....),there post...
7
2023
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 time to allow me to have the first option in the list a ‘listitem’ saying something like ‘please pick an option’, and then the rest of options...
5
4449
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) { if(Page.IsValid)
7
3333
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, theres a requirement to show a drop down menu list (this is a control I downloaded online) in one of the columns. For the purposes of this question,...
2
4536
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 set to...it is set to false. Can someone show me what I am doing wrong and tell me the correct way? Thank you. In the page load event, I am...
4
2025
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 listbox populates itself from a DB table, assigning the correct id to each item as a value. In between the listboxes are two buttons. On clicking an...
1
1577
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 second for to choose the value of the type when you choose a type a dropdownlist will be filled of values that related of that type. and when you...
0
7703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7618
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7926
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6287
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5223
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3657
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2117
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.