ASP .NET Reques.Form DropDownlist strange behavior - asp.net

I have an issue getting the selected value of a dropdownlist.
My view source looks like this:
<div class="editor-field">
<select class="list" id="DivisionesLists" name="DivisionesLists">
<option value=""> -- Seleccione -- </option>
<option selected="selected" value="1">COORPORATIVO</option>
<option value="2">MANUFACTURA</option>
</select>
</div>
And my controller:
string s = Request.Form["DivisionesLists"];
The problem is that Request.Form["DivisionesLists"] returns "1,1" instead of just "1" (which is the actual selected value of the dropdownlist).
What may be happening?
Thank you!!!

It might also be posting some additional data, what happens if you select the first one, what does it post back? Does it post anything back with a comma?
It could be a duplicate control... though like Html.CheckBox action method: it renders the checkbox control and a hidden field that represents the value when the checkbox isn't there; accessing the value when its checked is true,false.
HTH.

If the select isn't a multiple select I think you have another control (input or select) that have the same name attribute on the page.

Related

Trying to use a select value to save information

I used a select dropdown that is filled dynamically, based on conditions on country>state. But I can not get it out on context for the backend to properly save it to the database (selected value).
I can show the dropdowns correctly and save differently and correctly if I use a asp dropdownlist. Thing is, this code is imported and apparently all I can use if the select value.
<label for="country" class="col-form-label">Country: </label>
<select name="txtAddress_Country" class="countries order-alpha form-control" id="txtAddress_Country" runat="server">
<option value="">Select Country</option>
</select>
<label for="txtPersonal_FirstName" class="col-form-label">State: </label>
In the backend... this function works wonders with dropdownlist and text.
dbCampos.Save(u, new ASF.HC.JobApplication.Entity.Campo("txtAddress_Country", txtAddress_Country.Text));
So I am guessing the place to modify is the frontend.
I am guessing that I am missing some attribute but can not seem to find it. Says that it does not contain a definition for "Text" or accepting a first argument.
Maybe an initial value?
It is better to use instead of html with runat server.
secondly you can try as below:
dbCampos.Save(u, new ASF.HC.JobApplication.Entity.Campo("txtAddress_Country", txtAddress_Country.SelectedValue));
instead of:
dbCampos.Save(u, new ASF.HC.JobApplication.Entity.Campo("txtAddress_Country", txtAddress_Country.Text));

Classica asp: Checkbox and unhide dropdown control

I need to know how to handle the following scenario in Classical ASP. Please assist me with some sample as I am new to classical ASP
By default a dropdown control should be hidden
If Checkbox.value = Yes Then
Show the dropdown control with values
Else
Hide the dropdown control
End if
Regards,
It's actually quite simple - if your checkbox has the name attribute mycheckbox then you could use something like this
<% If Request.Form("mycheckbox") = "Yes" then %>
<select name="mydropdown">
<option value="1">Value 1</option>
<option value="2">Value 2</option>
<option value="3">Value 3</option>
</select>
<% End If %>
What you need to understand is that Classic ASP is server side - which means that the code is executed on the server rather than the browser. This means that in order to get your select dropdown to appear you'll need to post a form to the server and reload the page. If you want your dropdown to appear as soon as the checkbox is clicked then you should be looking for a client side solution with CSS and JavaScript.

How to select the item form the dropdownlist in gridview

I have the dropdownlist in the gridview itemtemplate, i need to select the value based on the dataset, i tried to bind it as "SelectedValue='<%# Eval("code") %>', but i cant find any attribute like "SelectedValue" in HTML code.
I tried below link also it was not work out to me
Eval() in a DropDownList within a GridView
Can any one help me in that
You have to understand how dropdown list (select tag) in HTML works.
E.g. if you want to select some item you have to mark it as selected as follows
<select>
<option value="a">a</option>
<option value="b" selected="1">b</option>
<option value="c">c</option>
</select>
So you have to put selected="1" to item you want to select. That means you can not do it easily using Eval method. You have to utilize server side which will do it for you.
The example given on the page you have postetd and which you said you have tried works correctly. Check whether the HTML output contains value attributes at each option. The value can differ from what is enclosed within the option tag. If the value attribute is missing that is the reason why the item is not being selected. (Use firebug or any developer console to examine).

How to disable multiple attribute in spring select tag

I have the following code:
<form:select path="roles" items="${roleList}" itemLabel="roleType" itemValue="id" />
It generates html as below:
<select id="roles" name="roles" multiple="multiple">
<option value="1">ROLE_ADMIN</option>
<option value="2">ROLE_HQ</option>
<option value="3">ROLE_MASTER</option>
<option value="4">ROLE_STATE</option>
<option value="5">ROLE_CENTRE</option>
</select>
Also I do not use the multiple optional attribute. Any idea why does the generated HTML contain "multiple="multiple" ?
Just a guess, but since you mapped it on roles, and since roles is probably a collection, it makes sense to make the select box multiple. If it was not multiple, you would only be able to store a single item in the collection. And the tag would not be able to display the selected roles.
EDIT: after reading the source code of the tag, it appears my guess was right. See the forceMultiple() method in SelectTag.

multiselect from dropdownlist for web app?

I'm building a web app that will come back with a report. For certain parameters where the user has requested a dropdown list, they also want to be able to select more than one option at a time.
e.g. show me all transactions from the states of TX, WV, and ID.
The reason I've decided to go with the dropdownlist they requested and not a listbox is there are over 40 parameters they can pick from and my page is already crammed with that many controls.
You won't be able to do it with a dropdownlist directly but what you could do is fake it.
Have a hidden ListBox on your page. Construct something that looks like a dropdownlist visually (label + image would work). During the onclick event of your fake dropdownlist show your listbox underneath your dropdownlist. Hide the listbox during the onblur event for the ListBox. Also you could throw in some jquery to animate the unveiling of your listbox to more closely match the look of a dropdownlist.
try this out: have a drop down for unselected choices and a list box for selected; similar to anton lavey's suggestions but slightly less elaborate.
<style>
select { width: 200px; }
</style>
<body>
<select id="sel" onchange="list.appendChild(this[this.selectedIndex]);">
<option disabled>Select items from this list</option>
<option value="a">a</option>
<option value="c">c</option>
<option value="d">d</option>
</select><br>
<select multiple="" id="list"><option value="b">b</option></select>
<button onclick="while(list.selectedIndex > -1) { sel.appendChild(list[list.selectedIndex]); }">Remove selected</button>
</body>
ordering can be preserved if you scan through to find the right spot to insert.

Resources