Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have a dropdownlist staff.

I try to select the option by its value property.

I get the value from the datareader correctly,but when i use the following code

dr_staff.SelectedItem.value=mydr("st_staff")

 

only the first option is selected.The correct option is not selected.

anybody pls help.

tx

Posted

yes.this is my dropdownlist

<asp:DropDownList AutoPostBack=True runat="server" DataTextField="st_staff_name" DataValueField="St_staff_id" id="dr_staff"></asp:DropDownList>

 

tx.

Posted

yes.this is my dropdownlist

<asp:dropDownList AutoPostBack=True runat="server" DataTextField="st_staff_name" DataValueField="St_staff_id" id="dr_staff"></asp:dropDownList>

 

tx.

Posted

This is the viewsource of my page after executing the command.

The value is 16.but it is not selecting the option joe.

tx

 

<select name="pc_staff" onchange="__doPostBack('dr_staff','')" language="javascript" id="dr_staff">

<option selected="selected" value="16">Select</option>

<option value="16">Joe,G</option>

<option value="17">Martin,L</option>

<option value="18">adsfasdf</option>

 

</select>

Posted

Actually... I'm sure that you populate your DropDownList in the Page_Load.

And I'm pretty sure that you don't verify the PostBack.

 

You must fill the DropDownList like this :

 

If( !this.IsPostBack )

{

// FILL YOUR DropDownList

}

 

when you refill your DDL and you try to get the current value... it'll always return the first one.

"If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown

"Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me

"A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend.

C# TO VB TRANSLATOR

Posted

yes.i am loading the dropdownlist only by checking ispostback method.here ismy code in the pageload event.

 

If Not Page.IsPostBack Then

sql3 = "select * from Nt_St_staff"

mycon3 = New SqlConnection(tq())

mycon3.Open()

mycmd3 = New SqlCommand(sql3, mycon3)

mycmd3.CommandType = CommandType.Text

mydr3 = mycmd3.ExecuteReader()

dr_staff.DataSource = mydr3

dr_staff.DataBind()

mycon3.Close()

End If

 

 

thanks

Posted

Oh... by the way... you have 2 value 16.

The first is called "Select" and the other is joe

 

try choosing another value for the first line.

"If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown

"Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me

"A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend.

C# TO VB TRANSLATOR

Posted

No.this is the viewsource of my page when it loads.but i click a button and try to select the option 16 or 17 say for eg. in my click event.then it selects only the first select option.

 

 

<select name="dr_staff" onchange="__doPostBack('pc_staff','')" language="javascript" id="dr_staff">

<option selected="selected" value="15">Select</option>

<option value="16">Joe,G</option>

<option value="17">Martin,L</option>

<option value="18">adsfasdf</option>

 

</select>

 

 

This is the viewsource after my click event.I don't know why it sets the value of the select option to 17 instead of selecting the 17th option

 

<select name=dr_staff" onchange="__doPostBack('pc_staff','')" language="javascript" id="dr_staff">

<option selected="selected" value="17">Select</option>

<option value="16">Joe,G</option>

<option value="17">Martin,L</option>

<option value="18">adsfasdf</option>

 

</select>

Posted
You'll have to show us more code... and maybe the part where you add the element "Select".

"If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown

"Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me

"A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend.

C# TO VB TRANSLATOR

Posted

I am populating the dropdownlist from my table Nt_st_staff in my pageload event

The design of the table is

 

st_Staff_id St_Staff_name

15 Select

16 Joe,G

17 Martin,L

18 adsfasdf

 

 

thanks

Posted

hai ,

my problem is solved using the following code with selectedindex.

thanks.

 

dr_staff.SelectedIndex=pp_staff.Items.IndexOf(dr_staff.Items.FindByValue(mydr1("dr_staff")))

Posted

Try dr_staff.SelectedValue=mydr("st_staff")

 

Best Regards,

 

Jay

 

I have a dropdownlist staff.

I try to select the option by its value property.

I get the value from the datareader correctly,but when i use the following code

dr_staff.SelectedItem.value=mydr("st_staff")

 

only the first option is selected.The correct option is not selected.

anybody pls help.

tx

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...