asp.net c# add html to dropdownlist [duplicate] - c#

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

Related

Setting Jquery Multiselect plugin properties from codebeind

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.

How to get the selected checkboxes which are dynamically generated using Jquery

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" )

asp.net textbox to html page data

Hi I'm a bit rusty with this again, I have a user profile web page and I'm working on making a wall posting system, I can do it the crappy n easiest way: textbox to listbox and then save the listbox as a text document for retrieval when the client logs in again.
But id like to write it to the HTML code or something of that nature. Like those div containers so my style sheet is applied to the data being posted.
Could anyone give me a head start to this?
You know from where you need to copy (sorry... take inspiration) your functionality.
Have a text box
User submits the data...
Add it to DB and either return the same data and add new table row below the previous one
or just on client add extra "TR" below the previous "TR".
It will require jQuery or any other similar thing. You have SO, dissect it using Firebug and build your own version of it.
You can do this with jQuery
$('button').click(function(){
var x = $('textarea').val();
$('div').html(x);
});
Check working example at http://jsfiddle.net/dzert/

user controls in asp.net prefixing string to child controls causing problem to refer them in javascript

I have user control in which there are text boxes no i am using the AJAX to populate the child controls dynamically however asp.net appending some string to child controls causing problems to write the JavaScript code. Though i have tried getElementLike('key') which iterate elements and get the right one for me but this is really inefficient. So if anybody has any insight on this issue please provide you input/suggestions.
Thanks all,
You will need to refer to those controls like this:
// typical way
var element1 = document.getElementById("<%= control.ClientID %>");
// jquery way
var element2 = $("#<%= control.ClientID %>");
Look at using someControl.ClientId, which will give you the ASP.NET generated id of the control. Using this Id you will be able to correctly target the element via javascript.
Use jquery to select the item using something like $("[id$='CWRCompanyId']"), this basically looks for id's that end with your expected ID.

tetxbox with drop down control and auto complete

in my Application i have text box beside it i have drop down control.
when the user clicks on the drop down . a list of items under the drop down control should be shown. but if user type any value in the text box ( like tom, james, peter). if that value is there in the drop down . i should move the cursor to that value.
hope my Question is clear.
Any solution how to solve it would be great
thank you
what are you looking is,
http://www.asp.net/AJAX/AjaxControlToolkit/Samples/ComboBox/ComboBox.aspx
Just check it, Its autocomplete with dropdown
Sounds like you want something like the JQuery autocomplete plugin or if you prefer the ASP.NET AJAX Autocomplete control.
Edit- as you want a Combobox- JQuery has a lot of options for this. Here is one of them "Simple Combo".

Categories

Resources