473,387 Members | 1,757 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 with a DropDownList

Hi

I have a DropDownList in a ASP.NET (C#) page. This control is bound to a DataTable to get the values to display
However, the SelectedItem never seems to change

For example, if I change manually the item selected in the DropDownList, then click a SubmitButton and then try to use the property this.ddlMyList.SelectedItem.Text, the value is still the value of the first item in the list. It never changes whatever I do

Please help me !!! :-

Jenny
Nov 18 '05 #1
4 1130
http://msdn.microsoft.com/library/default.asp?
url=/library/en-
us/dv_vjsharp/html/vjwlkwalkthroughusingdatagridwebcontrolt
oreadwritedatawithvisualj.asp
-----Original Message-----
Hi,

I have a DropDownList in a ASP.NET (C#) page. This control is bound to a DataTable to get the values to
display.However, the SelectedItem never seems to change!

For example, if I change manually the item selected in the DropDownList, then click a SubmitButton and then try
to use the property this.ddlMyList.SelectedItem.Text, the
value is still the value of the first item in the list. It
never changes whatever I do.
Please help me !!! :-)

Jenny
.

Nov 18 '05 #2
If you're binding the datatable to the drop down list
during the Page Load Event, ensure that the binding only
occurs when Page.IsPostback is false.

-----Original Message-----
Hi,

I have a DropDownList in a ASP.NET (C#) page. This control is bound to a DataTable to get the values to
display.However, the SelectedItem never seems to change!

For example, if I change manually the item selected in the DropDownList, then click a SubmitButton and then try
to use the property this.ddlMyList.SelectedItem.Text, the
value is still the value of the first item in the list. It
never changes whatever I do.
Please help me !!! :-)

Jenny
.

Nov 18 '05 #3
Duh! Yeah sorry that was a No Brainer!

I have this new problem: I'm trying to put some LinkButton inside a Datalist. But I can't add an event handler
for the button. If I double click on the LinkButton, I get forwarded to the method : dtlMyDataList_SelectedIndexChanged,
but that method is not fired when I click on one of the buttons at runtime.

How do I go about this? Or is it a bad idea to put a Link Button in a DataList in the first place?

thanks,

Jenny
Nov 18 '05 #4
Hi Jenny,

The DataList control also supports the ItemCommand event
that is raised when a user clicks a button that doesn't
have a predefined command such as edit or delete. You can
use this event for custom functionality by setting a
button's CommandName property to a value you need and then
testing for it in the ItemCommand event handler.
For example:
// C#
private void DataList1_ItemCommand(object source,
System.Web.UI.WebControls.DataListCommandEventArgs e)
{
if (e.CommandName == "AddToCart")
{
// Add code here to add the item to the shopping
cart.
// Use the value of e.Item.ItemIndex to find the
data row
// in the data source.
}
}

Bin Song, MCP
-----Original Message-----
Duh! Yeah sorry that was a No Brainer!

I have this new problem: I'm trying to put some LinkButton inside a Datalist. But I can't add an event
handlerfor the button. If I double click on the LinkButton, I get forwarded to the method :
dtlMyDataList_SelectedIndexChanged,but that method is not fired when I click on one of the buttons at runtime.
How do I go about this? Or is it a bad idea to put a Link Button in a DataList in the first place?
thanks,

Jenny
.

Nov 18 '05 #5

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

Similar topics

1
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: Olav Tollefsen | last post by:
I have a Web Form with a DataList. Inside the ItemTemplate, I have a DropDownList control. <asp:DataList ID="ProductDataList" Runat="server"> <ItemTemplate> <asp:DropDownList ID="DropDownList1"...
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...
3
by: Bas Paap | last post by:
I'm having a problem with formviews and DropDownLists in ASP.NET 2.0. I'm using a formview to insert an order into a database. Part of the order is the customer. Currently, I have a dropdownlist...
4
by: Savas Ates | last post by:
I have a datagrid control and in my edit item template tag I have ,
0
by: ana_gil | last post by:
hello i have a problem with a dropdown list i am populating from an Access table. I´ve seen this problem in other discussions but i can´t seem to find the solution. please help. my .aspx has...
10
by: Dan | last post by:
Hi, I create 5 dropdownlist in code-behind. I want to insert their selectedvalues in a table by making a string separated with ":" I can get their selecedvalues but i'm stuck when i want to...
4
by: pankajsingh5k | last post by:
Hi guys, These question is for all the experts... Please help me before my brain explodes The problem is again with the formview control.. I have a formview and i have to use it that...
2
by: pankajsingh5k | last post by:
Dear All, Please help me... I had read an article to lazy load a tab in a tabcontainer using an update panel on http://mattberseth.com/blog/2007/07/how_to_lazyload_tabpanels_with.html ...
6
by: shashi shekhar singh | last post by:
Respected Sir, I have to create multiple dynamic dropdownlist boxes and add items dynamically in <asp:table> server control but problem occurs , i.e. except of fist dropdown list no dropdownlist...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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.