473,583 Members | 3,114 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


Sep 19 '05 #1
1 1985
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

Sep 19 '05 #2

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

Similar topics

5
1258
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
1971
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
2026
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
1176
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" CommandName="Delete"></asp:ButtonColumn> would become :
7
3334
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
2175
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...
2
4541
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
7896
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
7827
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
8184
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
8328
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
8195
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6581
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...
1
5701
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3820
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
1158
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.