Link to home
Start Free TrialLog in
Avatar of paulwhelan
paulwhelan

asked on

Starter website question

Hi
I created a page with a dropdownlist and a textbox.
I wanted to fill the textbox with some text depending on what is selected in the dropdownbox.

My code is below.

I double clicked on the dropdownbox and I thought this would work.

Thanks
Paul

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (DropDownList1.Text == "paulwhelan")
            TextBox1.Text = "Male";
        else
            TextBox1.Text = "Female";
    }
}


ASKER CERTIFIED SOLUTION
Avatar of newnewmommon
newnewmommon

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MuhammadAdil
Check the property (IsPostBack) of web page.
Avatar of paulwhelan
paulwhelan

ASKER

thanks

just one more thing

should i use

DropDownList1.Text
or
DropDownList1.Value

Whats the difference?

Thanks
Paul
the same thing

but i use this all time

DropDownList1.SelectedValue.Equals("paulwhelan")
if ur r binding drordownlist with datasource
there are different properties DisplayMember and ValueMember
u can assign these same field of two different fields
 such as
 myDropdown.datasource = ds.Customer (ds -- DataSet)
 myDropdown.DisplayMember = "CustomerName"
 myDropdown.ValueMember = "CustomerID"  for same  myDropdown.ValueMember = "CustomerName"

myDropdown.SelectedText will be Displaymember values
myDropdown.SelectedValue will be Valuemember values
 

Best regards
SelectedText  mean the value that the Client will see it
SelectedValue mean the value will use with this text

example if u have dropdownlist  with all country in the world and u select (United State)
SelectedText  =United State
SelectedValue =US

all developer use SelectedValue to save small value in the database
I see

DropDownList1.SelectedIndex
DropDownList1.SelectedItem
DropDownList1.SelectedValue

Are they all different?

Thanks
Paul