I set the drop down selected value using jquery, but when trying to access this value on c# it getting null.
Jquery to set selected value:
$([id*=ddl]).val(1);
Asked
Active
Viewed 216 times
3

Naqi
- 144
- 2
- 9
-
You need to pass the selector in quotes `$('[id*=ddl]').val(1)`, assuming it typo when posting question, However `val(1)` should work – Satpal Sep 30 '16 at 05:33
-
Is the drop down value visually changing on the page when that JS is executed? – Dan Def Sep 30 '16 at 06:13
-
I am using $('[id*=ddl]').val(1) – Naqi Oct 01 '16 at 04:13
-
No Def, it id not changing – Naqi Oct 01 '16 at 04:24
-
@Naqi if the ddl is not changing it means your selector isn't getting the drop down list or there is no option with value 1. Make sure after calling `$([id*=ddl]')` that your select is in the array. Also, in the C# it is the SelectedValue property you want. – Dan Def Oct 01 '16 at 13:21
1 Answers
3
Since you have a dropdown(select), you need to find the option with the value of 1 and select i using the selected
property
$('[id*=ddl]').find('option[value="1"]').prop('selected',true);

Satpal
- 132,252
- 13
- 159
- 168

madalinivascu
- 32,064
- 4
- 39
- 55
-
I have tried this but still not working."ddl.SelectedItem" on c# showing null. – Naqi Oct 01 '16 at 04:16