Hi i have a page which consists of dynamically generated checkboxes using razor code. I need to get the selected checkboxes using Jquery. If there is anything simple than Jquery to achieve this means suggest me.
you can get Check box status (checked/Unchecked) in Jquery like this
$('[type="checkbox"]').each(function(){
alert($(this).is(":checked"))
});
$( "input[type=checkbox] :checked" )
Related
I have been searching for a couple of hours to try to fix this.
I am using the Select2 jquery plugin to get a dropdown with multiple select.
The problem is that the first option is always selected.
I have tried to use the tag multiple="multiple" but ASP.NET doesn't know what is that, only allow me to make it multiple="true" or multiple="false"
Any suggestion??
By default Select2 should not be preselecting any value, so my guess is that you are setting the selected value somewhere, probably in the c# code where you are populating the drop down with values. So try to clear the selected index in the Page_Load method
slEmployeeRole.SelectedIndex = -1 or in the js document ready part of the page, try clearing the drop down just to be sure that nothing is selected. And use multiple="true". $('#slEmployeeRole').val(null).trigger('change');
Hi I want to put image along with some data in asp.net drop down list box.
Can somebody give me a sample code to achieve this functionality?
country flag + country name --> in the same list item
You could use jQuery Image Dropdown:
http://marghoobsuleman.com/jquery-image-dropdown
(source: marghoobsuleman.com)
<script language="javascript">
$(document).ready(function(e) {
try {
// target some ids
MSDropDown.init("#combo1, #combo2");
//by wild card
MSDropDown.init("#divid select");
//or
MSDropDown.init("#formid select");
} catch(e) {
alert(e);
}
})
</script>
I haven't tried to use this JQuery Combo-Box, but from the screenshot, it looks like the items in the combo box can include an image in it. Maybe you could research more regarding this.
With standart dropdownlist, you can not achive this.
You need to write a custom server control that is not based on dropdown list.
You cannot achieve this with a raw drop down list / combo box in C#. The underlying control only supports text and not a combination of text + image.
You'll either need to write a custom control or use something like jQuery to build the drop down with your code populating the results.
That's right, standard tool doesn't accept images, try with a custom tool.
try with this free tool: http://controlsbuilder.com/tools/CustomDropDownList.aspx
Is it possible to set jquery Multiselect plugin properties from codebeind?
I have created a asp.net web user control which shows multiselect jquery dropdown with checkboxes. I am using this control on different places on same page and want to adjust the width of each dropdown. Don't know if it is possible to have a control property in code behind which will change the width of multiselect dropdown.
$("select").multiselect({
selectedText: "--Select ALL--",
minWidth: '300'
});
You can insert javascript in your page that can do that work, but you will need to know the id of each select element to do that.
But I wouldn't recommend this.
The best would be to set the property in your html rather than calling javascript.
Adding more info to ppetrov's answer, you can wrap javascript statements to a function. Like following
function SetSize(size)
{
$("select").multiselect({
selectedText: "--Select ALL--",
minWidth: size
});
}
In serverside code, you can use following to set size.
ClientScript.RegisterStartupScript(typeof(Page), "scrpt", string.Format("SetSize({0});","100"), true);
Assuming you need to do this for all select element,as you have specified this in selector.
But, it is best practice to handle everything in clientside code ( JS) , since you need to handle something in JS.
I am looking for a textbox in C# which should work like dropdown search values when I type anything in the textbox. Those values will come from calling a method.. and I Should be able to select any of the values.
Do i need to use the asp dropdownlist or is there any other sample code available which could help me.
You should look into jQuery autocomplete feature.
http://jqueryui.com/autocomplete/
The ajax control toolkit provides Autocomplete extender to do just that. The control calls a method, which you specify, asynchronously and get all the values to be shown as an option. I would imagine these values would be retrieved when the page loads and will not be session specific so can be stored in a cache for faster retrieval.
http://www.asp.net/AjaxLibrary/AjaxControlToolkitSampleSite/AutoComplete/AutoComplete.aspx
How can I create a dynamic drop down list without using AutoPostBack. I ask because I just want to change the value of what the second drop down list displays and then the user clicks a button and it submits. But If I use AutoPostBack then it postbacks to page and runs code that shouldn't be run until that final box has been selected. (I use Postback in the other part of my program so using !IsPostBack isnt a option.) I looked at Javascript but ASP generates all of its controls names at runtime. What can I do? I have looked at the Ajax CascadingDropDown control but my problem with that is it contained in a XML file or a Database, I need this to be contained inside my Page. Any Ideas?
You can use the CascadingDropDown control from the AJAX Control Toolkit
Maybe this example will help? It's part of the ASP.NET AJAX Control Toolkit available here.
You can use AJAX to get the values for the second drop down list, based on the selected value of the first. Add a onchange event handler on the client-side to the first drop down list that makes the AJAX call and fills the second on success.