开发者

making some items unselectable in dropdownlist using asp.net?

Dropdownlist i binded the values but in that dropdownlist just like group means(employee,nonemployee) so that items value is empty(""), so i can use databound event split the two fileds ,that two fields i can apply the color and underline and bould and user doesnot select that fields , so pls see the below code and modify this code.

protected void ddlconsultant_DataBound(ob开发者_Go百科ject sender, EventArgs e) { foreach (ListItem item in ((DropDownList)sender).Items) {

string r = item.Value; if (r == "") {

item.Attributes.Add("style", "color:Red;font-weight:bolder"); } }

thanks hemanth


I'm handling this situation on the client side, using javascript, actually jQuery

jQuery(document).ready(function () {
        $("[id*=ddlConsultant] option[value='']").each(function () {
            $(this).attr("disabled", "true");
            $(this).css("color", "Red");
            $(this).css("font-weight", "bolder");
        });
    });


It's probably easier to do this with server-side code, in the same place where you set the colour of list items:

item.Attributes.Add("style", "color:Red;font-weight:bolder");
item.Attributes.Add("disabled", "disabled");

This will product HTML code that looks something like this:

<option style="color:Red;font-weight:bolder" disabled="disabled">item text</option>

I know this is kinda an old question, but I've just been looking for the same information, and having just found out, thought I'd add the answer here for completeness.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜