473,386 Members | 1,819 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,386 software developers and data experts.

DropDown1.SelectedItem.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(object sender, System.EventArgs e)

{

if(Page.IsValid)

{
Response.Write(DropDown1.SelectedItem.Value);
}

}

what's wrong?

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

Sample code for ref

private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
DropDownList1.Items.Add("1");
DropDownList1.Items.Add("2");
DropDownList1.Items.Add("3");

}
}
private void Button1_Click(object sender, System.EventArgs e)
{
if(Page.IsValid)
{
Response.Write(DropDownList1.SelectedItem.Value );
}
}
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.jpg">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***@discussions.microsoft.com> wrote in message
news:BA**********************************@microsof t.com...
Hi Edsvik,
Just check if you are rebinding the data on PostBack.

Sample code for ref

private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
DropDownList1.Items.Add("1");
DropDownList1.Items.Add("2");
DropDownList1.Items.Add("3");

}
}
private void Button1_Click(object sender, System.EventArgs e)
{
if(Page.IsValid)
{
Response.Write(DropDownList1.SelectedItem.Value );
}
}
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(object sender, System.EventArgs e)

{

if(Page.IsValid)

{
Response.Write(DropDown1.SelectedItem.Value);
}

}

what's wrong?

/Lasse

Nov 18 '05 #4
call that function on page load like
if (!Page.IsPostBack)
{
//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.jpg">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***@discussions.microsoft.com> wrote in message
news:BA**********************************@microsof t.com...
Hi Edsvik,
Just check if you are rebinding the data on PostBack.

Sample code for ref

private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
DropDownList1.Items.Add("1");
DropDownList1.Items.Add("2");
DropDownList1.Items.Add("3");

}
}
private void Button1_Click(object sender, System.EventArgs e)
{
if(Page.IsValid)
{
Response.Write(DropDownList1.SelectedItem.Value );
}
}
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***@discussions.microsoft.com> wrote in message
news:3C**********************************@microsof t.com...
call that function on page load like
if (!Page.IsPostBack)
{
//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.jpg">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***@discussions.microsoft.com> wrote in message
news:BA**********************************@microsof t.com...
Hi Edsvik,
Just check if you are rebinding the data on PostBack.

Sample code for ref

private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
DropDownList1.Items.Add("1");
DropDownList1.Items.Add("2");
DropDownList1.Items.Add("3");

}
}
private void Button1_Click(object sender, System.EventArgs e)
{
if(Page.IsValid)
{
Response.Write(DropDownList1.SelectedItem.Value );
}
}
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
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. ...
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...
4
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...
6
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...
4
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...
4
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...
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...
1
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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: 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
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,...
0
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...

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.