Saturday, March 24, 2012

CascadingDropDown suggestion

Hi.

Over at CodePlex, I was told to post suggestions here for the community to comment on. So, any comments?

I have a custom control called FirstItemDropDownList that allows you to set the first item to something like "Select an item". That is the text for the dropdown. The value is a GUID that is always the same so that in code I can tell if the selection is still on the first item by the GUID value. The CascadingDropDown extender has a PromptText property to set the "Select an item" text. However, it does not allow the value to be set, so I added a PromptValue property. Here are the changes to enable this feature:

In CascadingDropDownExtender.cs, add:

///<summary>

/// Optional text displayed by a DropDownList the user has not yet touched

///</summary>

[DefaultValue("")]

[ExtenderControlProperty()]

publicstring PromptValue

{

get {return GetPropertyValue<string>("PromptValue",""); } set { SetPropertyValue<string>("PromptValue",value); }

}

In CascadingDropDownBehavior.js, add:

this._promptValue =null;

and:

get_PromptValue :function() {

/// <value type="String">

/// Value for the prompt text displayed as the first entry in the drop down

/// </value>

returnthis._promptValue;

},

set_PromptValue :function(value) {

if (this._promptValue != value) {

this._promptValue = value; this.raisePropertyChanged('PromptValue');

}

},

and change:

var optionElement =new Option(headerText,"");

to:

var optionElement =new Option(headerText,this._promptValue);

You can the do something like this:

<ajaxToolkit:CascadingDropDownID="CascadingDropDown1"TargetControlID="DropDownList1"

runat="server"Category="Make"LoadingText="[Loading makes...]"

PromptText="-- Please select a make--"PromptValue="SomeUniqueValue"

ServiceMethod="GetDropDownContents"ServicePath="CarsService.asmx">

</ajaxToolkit:CascadingDropDown>

Does anyone else find this useful, or feel it should be added to the extender?

Thanks,

Carl

hi

i want to set the prompt text value if you get this code then please send me

please..............

thanks


Hi, Zarana.

Did you try out the code changes I documented above? Did you have any trouble getting it to work?

Thanks,

Carl


hi Carl,

i am using dll of ajax so this solution is not work. have you any other solution then please reply me.

Please

Thanks

Zarana.


ah...well, I am not on the development team, so I don't have any way to produce the dll distributable version, other than to compile the source myself, and I have other customizations that are unique to my environment. But if you download the source, open the solution in Visual Studio, and apply the changes that I have documented above, you can then create the dll's yourself. I believe you said in another post that you needed it in VB, but I don't use VB so I can't help you there. But, again, making the changes documented above should be straightforward even without knowing C#. If you would like, I could send you the complete .js and .cs files with my changes already made. Then all you would have to do is replace the ones that are there and build the solution.

As you probably know, once you build the dll's, a VB application can talk to a dll created in C# with no problems.

Hope this helps,

Carl


hi Carl,

ya i want that both files.Please send me.

Thanks

Zarana


Okay, what's your email address and I'll send them to you.

No comments:

Post a Comment