Auto click option value using webbrowser in c# - c#

I have code Html as following:
<select name="film_episode">
<option value="1111">Post 1</option>
<option value="2222">Post 2</option>
<option value="3333">Post 3</option>
</select>
how to use 'webbrowser' in c# click on selected automatically 'Post 2'.
Please help me. Thank you very much.

Use this to get things easier
<select runat="server" id="dropDownList1" name="film_episode">
<option value="1111">Post 1</option>
<option value="2222">Post 2</option>
<option value="3333">Post 3</option>
</select>
in Code behind(aspx.cs)
dropDownList1.Items.FindByText("Post 2").Selected = true;

Related

How to show a message with the selected items with a Bootstrap Select List C# ASP .NET

I need to know a way to show an alert with all the selected items after pressing a button, could be with the code behind or jQuery, any of them work, this is a sample:
<label for="sel2">Mutiple select list (hold shift to select more than one):</label>
<select multiple class="form-control" id="sel2">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
The output should be a regular alert with all the selected items, thanks in advance.
(Edit: Wrong sample)
HTML :
<div class="form-group">
<label for="sel1">Select list:</label>
<select class="form-control" id="sel1" multiple>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<button type="button" id="btn">Alert Selected</button>
</div>
Script
<script>
$("#btn").click(function(){
alert($("#sel1").val());
});
</script>

ASP.NET Core Tag Helper Arrays

I have an ASP.NET Core 2.0 web application that generates a multi-select list box using bootstrap-multiselect (basically a prettied up list box control)
The code generated is shown:
<select class="multiselect-ui form-control" id="Issues" multiple="multiple" name="Issues">
<option selected="selected" value="1">Dilapidated Structures</option>
<option selected="selected" value="3">Junk on Premises</option>
<option selected="selected" value="4">Junk Vehicles</option>
<option selected="selected" value="5">Minor Maintenance</option>
<option selected="selected" value="6">Miscellaneous</option>
<option selected="selected" value="7">Overgrowth</option>
<option selected="selected" value="8">Right of Way</option>
<option selected="selected" value="9">Sidewalks</option>
<option selected="selected" value="10">Trash</option>
<option selected="selected" value="2">Weeds/High Grass</option>
</select>
When this is submitted in a form, I see the Issues being added to the URL like so:
/Cases?Issues=1&Issues=3&Issues=4&Issues=5 ...
This is great and I am able to retrieve the values in my controller using a List<string> object. My question is, how would I add a hyperlink to the page that uses the values already sent via GET? Basically I would like to use Tag Helpers, but there is no way to add an array of values that I've found. There are dictionary key/pairs, but of course you are not able to add multiple values with the same key. I would like to be able to reference a List<string> in the tag helper itself (the following does not work, but should give an idea of what I'm after if I am sending the List<string> back using ViewBag):
<a asp-route-Issues=#ViewBag.IssuesList>Next</a>
I found out through this link that this feature isn't implemented. I used #Url.Action to build my link as shown (where ViewBag.IssuesList contains the List<string> -- I also left out some paramters for brevity:
Previous

How to selected drowndown list options in web browser

Im working a web browser automation project.
this is exampel code ;
<select name="ctl00$ctl00$main$Content$cbReceiverCity" id="ctl00_ctl00_main_Content_cbReceiverCity" tabindex="40" class="custom-select" onchange="javascript:GetTowns(this);void(0);" style="width:170px;" size="5">
<option selected="selected" value="-1">-- choose one --</option>
<option value="1">Portugal</option>
<option value="2">Spain</option>
<option value="3">France</option>
<option value="4">Germany</option>
<option value="5">Italy</option>
</select>
and my c# code;
HtmlElement enter =
webBrowser1.Document.GetElementById("ctl00_ctl00_main_Content_cbReceiverCity");
enter.SetAttribute("selectedIndex", "5");
enter.InvokeMember("onchange");
but,Index value does not change. How can I change this?
Replace this
enter.SetAttribute("selectedIndex", "5");
with this
enter.Children[5].SetAttribute("selected", "selected");
where 5 is the index of the option you want to select

C# - Webkit - Select a html dropdown item without selected attribute

I need help. How can i select a dropdown item that does not have the selected attribute in C# using Webkit? The html is :
<select id="question" name="questionId">
<option value="">Text</option>
<option value="1">
Question 1
</option>
<option value="2">
Question 2
</option>
</select>

Change selected value from a DropDownList of Razor with JQuery

I would like to modify the selected value of my dropdownlist without have to click on my dropdownlist.
I already tried this line with JQuery:
$('#select-nb-Persons-button').children(":first").text("3");
It printed well "3" for the dropdownlist but after, when I clicked on the dropdownlist, I noticed that it is always the first option tag that is selected and not the third option tag as I want. :
Code created by razor for the dropdownlist :
<div class="ui-select">
<div id="select-nb-Persons-button" class="ui-btn ui-icon-carat-d ui-btn-icon-right ui-corner-all ui-shadow">
<span>1</span>
<select data-val="true" data-val-number="Le champ nbPersons doit ĂȘtre un nombre." data-val-required="Le champ nbPersons est requis." id="select-nb-Persons" name="nbPersons">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
</div>
</div>
Can you help me please ?
Thank you
You can use val() to set the selected item in a select. To select the item with a value of 3, try this:
$('#select-nb-Persons').val('3');
Try below code.
$('#select-nb-Persons-button').children('select').val('5');
DEMO here

Categories