Showing posts with label community. Show all posts
Showing posts with label community. Show all posts

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.

CascadingDropDown selectindexchanged problem with iframe

Hi community,

i implement the CascadingDropDown code into my application and it works correct. So where is the problem ? :)
in my programm i have two aspx sites one with dropdownlist and an iframe(where the Piechart is displayed),
and a second for Piechart Drawing.
The iframe is in the updatepanel and the ImageUrl is empty
What i add to the selectindexchanged Event is a db connect with handels with the dropdownlist choise

Added Code selectindexchanged Event from the first site

Session("bezeichner") = bezeichner
Session("anzahl") = anzahl
Session("i") = i
iframe.ImageUrl = "Piechart.aspx"

Code from the second site

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim bezeichner = Session("bezeichner")
Dim anzahl = Session("anzahl")
Dim i = Session("i")
Dim count = Session("count")
CreatePie(bezeichner, anzahl, i, count)

End Sub

Now i choose a item from the CascadingDropDown: the db connect process starts, the Sessionvariable gets filled and the PieChart is drawing in the iframe..
After that, i select a different item from the CascadingDropDown and "nothing" happens...to the iframe

But the Label1.Text(joe's tutorial) shows me the correct result.

So whats wrong ?

Thanks for any help!

Simon A.

Hi Simon,

I made a sample according to your description, and it worked fine.

Please try it and compare with yours:

Default.aspx

<%@. Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void Page_Load(object sender, EventArgs e) { Label1.Text = DateTime.Now.ToString(); Label2.Text = DateTime.Now.ToString(); } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { Session["index"] = DropDownList1.SelectedIndex; }</script><html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server"> <title>Hover Sample</title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager><div> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" Width="188px"> <asp:ListItem>1</asp:ListItem> <asp:ListItem>2</asp:ListItem> <asp:ListItem>3</asp:ListItem> </asp:DropDownList> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label> <iframe id="iframe1" runat="server" src="Default2.aspx"></iframe> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="DropDownList1" /> </Triggers> </asp:UpdatePanel> </div> </form></body></html>

Default2.aspx

<%@. Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void Page_Load(object sender, EventArgs e) { Response.Write(Session["index"].ToString()); // draw the pie based on the value of Session["index"] here }</script><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div> </div> </form></body></html>

HiRaymond,

Big thanks for your help, it works fine now!

best regards,

Simon A.