473,699 Members | 2,386 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DropDown1.Selec tedItem.Value.. .....

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(o bject sender, System.EventArg s e)

{

if(Page.IsValid )

{
Response.Write( DropDown1.Selec tedItem.Value);
}

}

what's wrong?

/Lasse
Nov 18 '05 #1
5 4453
Hi Edsvik,
Just check if you are rebinding the data on PostBack.

Sample code for ref

private void Page_Load(objec t sender, System.EventArg s e)
{
if (!Page.IsPostBa ck)
{
DropDownList1.I tems.Add("1");
DropDownList1.I tems.Add("2");
DropDownList1.I tems.Add("3");

}
}
private void Button1_Click(o bject sender, System.EventArg s e)
{
if(Page.IsValid )
{
Response.Write( DropDownList1.S electedItem.Val ue );
}
}
HTH
srini
"Lasse Edsvik" wrote:
Hello

I have a dropdown with 3 different values, and it prints out first value no


Nov 18 '05 #2
srini,

not sure what you mean....... if i check the source its there:

<select name="Textures" id="Textures">
<option value="gold.jpg ">gold.jpg</option>
<option value="goldwave .jpg">goldwave. jpg</option>
<option value="rocks.jp g">rocks.jpg </option>
</select>
and in the Page_Load i call a function that generates that droplist.......

but it doesnt work...... always prints first value (gold.jpg) in droplist
when i click the button......


"srini" <sr***@discussi ons.microsoft.c om> wrote in message
news:BA******** *************** ***********@mic rosoft.com...
Hi Edsvik,
Just check if you are rebinding the data on PostBack.

Sample code for ref

private void Page_Load(objec t sender, System.EventArg s e)
{
if (!Page.IsPostBa ck)
{
DropDownList1.I tems.Add("1");
DropDownList1.I tems.Add("2");
DropDownList1.I tems.Add("3");

}
}
private void Button1_Click(o bject sender, System.EventArg s e)
{
if(Page.IsValid )
{
Response.Write( DropDownList1.S electedItem.Val ue );
}
}
HTH
srini
"Lasse Edsvik" wrote:
Hello

I have a dropdown with 3 different values, and it prints out first value
no

Nov 18 '05 #3
Dear Lasse,

Where are you populating your Dropdownlist. I think you are doing it at the
page_load event.

If so, you need to put the code between

if(!IsPostBack)
{
code to populate your dropdownlist
}

thats bcos, each time you click the button, the page is posted back and
loads the page. hence, it will refill the dropdownlist.

if you give it within the above code, then the dropdown will be filled only
when the page is first time loaded and not each time it is posted back.

hope it helps.

"Lasse Edsvik" wrote:
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(o bject sender, System.EventArg s e)

{

if(Page.IsValid )

{
Response.Write( DropDown1.Selec tedItem.Value);
}

}

what's wrong?

/Lasse

Nov 18 '05 #4
call that function on page load like
if (!Page.IsPostBa ck)
{
//Call function here
}
HTH
srini

"Lasse Edsvik" wrote:
srini,

not sure what you mean....... if i check the source its there:

<select name="Textures" id="Textures">
<option value="gold.jpg ">gold.jpg</option>
<option value="goldwave .jpg">goldwave. jpg</option>
<option value="rocks.jp g">rocks.jpg </option>
</select>
and in the Page_Load i call a function that generates that droplist.......

but it doesnt work...... always prints first value (gold.jpg) in droplist
when i click the button......


"srini" <sr***@discussi ons.microsoft.c om> wrote in message
news:BA******** *************** ***********@mic rosoft.com...
Hi Edsvik,
Just check if you are rebinding the data on PostBack.

Sample code for ref

private void Page_Load(objec t sender, System.EventArg s e)
{
if (!Page.IsPostBa ck)
{
DropDownList1.I tems.Add("1");
DropDownList1.I tems.Add("2");
DropDownList1.I tems.Add("3");

}
}
private void Button1_Click(o bject sender, System.EventArg s e)
{
if(Page.IsValid )
{
Response.Write( DropDownList1.S electedItem.Val ue );
}
}
HTH
srini
"Lasse Edsvik" wrote:
Hello

I have a dropdown with 3 different values, and it prints out first value

no


Nov 18 '05 #5
thx for helping
"srini" <sr***@discussi ons.microsoft.c om> wrote in message
news:3C******** *************** ***********@mic rosoft.com...
call that function on page load like
if (!Page.IsPostBa ck)
{
//Call function here
}
HTH
srini

"Lasse Edsvik" wrote:
srini,

not sure what you mean....... if i check the source its there:

<select name="Textures" id="Textures">
<option value="gold.jpg ">gold.jpg</option>
<option value="goldwave .jpg">goldwave. jpg</option>
<option value="rocks.jp g">rocks.jpg </option>
</select>
and in the Page_Load i call a function that generates that droplist.......
but it doesnt work...... always prints first value (gold.jpg) in droplist when i click the button......


"srini" <sr***@discussi ons.microsoft.c om> wrote in message
news:BA******** *************** ***********@mic rosoft.com...
Hi Edsvik,
Just check if you are rebinding the data on PostBack.

Sample code for ref

private void Page_Load(objec t sender, System.EventArg s e)
{
if (!Page.IsPostBa ck)
{
DropDownList1.I tems.Add("1");
DropDownList1.I tems.Add("2");
DropDownList1.I tems.Add("3");

}
}
private void Button1_Click(o bject sender, System.EventArg s e)
{
if(Page.IsValid )
{
Response.Write( DropDownList1.S electedItem.Val ue );
}
}
HTH
srini
"Lasse Edsvik" wrote:

> Hello
>
> I have a dropdown with 3 different values, and it prints out first
value no


Nov 18 '05 #6

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

Similar topics

1
15347
by: gordon | last post by:
Hi I have a combo box that my application uses to select an item for a regression function. I would like to convert the selected item to a string value and use this value later in my code. I have used private string charVal;
0
1982
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 an error " System.NullReferenceException: 佫¶ÔÏóÒýÓÃÉèÖõ½¶ÔÏóµÄʵÀý¡£", I Don't know the...
4
1712
by: Ivan | last post by:
Hi, I have a problem with a page which has about 50 web controls , 12 of the are DropDownList. Also, I have a "Continue" button, and on the server code an event sub btnContinue_Click, where I process the input data. There is a code like : Dim MyVariable As Integer Dim AnOtherVariable As Integer MyVariable = DropDownList1.SelectedItem.Value
6
5532
by: Julius Fenata | last post by:
Dear all, I have created client-side scripting to trigger event onChange from code-behind, like this: DropDownList1.Attributes = "GenerateArticleID()"; At the script on Windows Form, I added this function to have the value of DropDownList1
4
2103
by: Martyn Fewtrell | last post by:
I want to update a database record with a number of fields - doesn't sound to difficult at this stage! I have a system to select the correct record from the database and load the data into a form across a number of text boxes and a single drop down list (the idea being that the text boxes can be edited and the drop down listed altered to reflect a new value if necessary). The drop down list in the form is loaded from the appropriate...
4
3472
by: darrel | last post by:
what is the difference between these? I always end up typing 'selectedvalue' only to have problems and then realize I meant to use selecteditem.value (the value of the selected item). When would one use the former (selectedValue)? -Darrel
2
2182
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 server I've this strange code : <select name="MyDataCampi:_ctl1:ComboTipoPartita"...
1
3012
by: RSH | last post by:
Hi, I am experimenting with the Viewstate and based on a few articles I have read, I put together a test. it is a simple test where I am dynamically creating a DropDownList that contains 25000 list items. When I don't create the control dynamically, I get a viewstate that is roughly 1 mb in size! However, when i use the code below the viewstate is 0 bytes even on postback. Impressive size difference. Now where I get perplexed is even...
2
7086
by: Tracey | last post by:
How can I convert to a string (what I thought was a string)? and/or How can I assign the value of a selected item in a list box to Label1.Text? using VB in VS2005. Thanks, Tracey I completed a {simple} class project that displays the value of what was clicked in a List Box (which appears at the top of the page): Response.Write("You clicked ")
0
8685
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8613
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8880
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7745
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6532
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5869
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3054
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
2
2344
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2008
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.