Showing posts with label selectedvalue. Show all posts
Showing posts with label selectedvalue. Show all posts

Wednesday, March 28, 2012

Change dropdown selectedvalue in usercontrol, in a page.aspx

Hello,

i have a usercontrol (reservas.ascx) with one dropdown list (dropHoteis) inserted in one masterPage.
In my default.aspx, that is a content page of that masterPage...
How can i change the selected value in the dropdown list (dropHoteis) from my default.aspx?

1. In reservas.ascx, i put the Class Public...
2. In Default.aspx.vb, how can i reference the reservas.ascx?? I tryed, but not appear in my @dotnet.itags.org.Imports... why?

Thanks for your help!

From the page you can useMe.Master.FindControl("IdOfUserControl") which will get you the reference to your user control.

-Damien


Hep, ok...

But in my UserControl how can i declare the "function/property" to change the selectedValue of the dropdownlist??

Example:

Public Property DropSelectedValue(ByVal hotelAs String)Set(ByVal value) dropHoteis.SelectedValue = valueEnd Set Get dropHoteis.SelectedValue = hotelReturn dropHoteis.SelectedIndexEnd Get End Property

This not work for me!! :(

throw: Object reference not set to an instance of an object!!


in the usercontrol's code behind write a public property in which you have to set the dropdown list's value. u can then access that property from your page.aspx using the usercontrol name and can set the value of the dropdown list.

Regards & have a nice day ahead

Monday, March 26, 2012

CascadingDropDownProperties - Setting SelectedValue dynamically

I have an application where I am using the CascadingDropDown Lists. I have incorporated a set of them into a control.

I want to add a property to my CascadingDropDownProperties that will set an initial "filter" for my list.

For example, if I were using the sample CDD provided on the website that gives Make, Model, Color in my application, I may want to tell my control to only select foreign or domestic makes. At this point, the control can continue on to do what it needs to.

My web method is calling a MS-SQL stored procedure, and it has an input parameter of foreign/domestic (CarClass) for selecting the available Makes.

My questions on this are as follows:

    How do I set up my CascadingdropDownProperties to add the Foreign/Domestic (CarClass) value?

    How do I set this value in the code-behind?

(I will omit my actual DropDownLists from my code.)

Here is my CascadingDropDown definition:

1 <atlasToolkit:CascadingDropDown ID="CascadingDropDown1" runat="server">
2 <atlasToolkit:CascadingDropDownProperties
3 Category="CarClass"
4 ServicePath="~/wsSelectCar_Data.asmx" />
5
6 <atlasToolkit:CascadingDropDownProperties
7 TargetControlID="ddlMake"
8 Category="Make"
9 PromptText="Please select a Make"
10 ServiceMethod="GetMakes"
11 ServicePath="~/wsSelectCar_Data.asmx" />
12
13 <atlasToolkit:CascadingDropDownProperties
14 TargetControlID="ddlModel"
15 ParentControlID="ddlMake"
16 Category="Model"
17 PromptText="Please select a Model"
18 ServiceMethod="GetModel"
19 ServicePath="~/wsSelectCar_Data.asmx" />
20
21 <atlasToolkit:CascadingDropDownProperties
22 TargetControlID="ddlColor"
23 ParentControlID="ddlMake"
24 Category="Color"
25 PromptText="Please select a Color"
26 ServiceMethod="GetColor"
27 ServicePath="~/wsSelectCar_Data.asmx" />
28 </atlasToolkit:CascadingDropDown>

As you can see, I tried to create a property with the Category "CarClass". My Code-behind has the following to try to set the value:

1 int intCarClass =int.Parse(Session["CarClass"].ToString());
2 this.CascadingDropDown1.TargetProperties[0].SelectedValue = intCarClass.ToString();

This does not seem to work.

Thanks,
Bryan

Hi Bryan,

I'd recommend you switch to a page method and then just check whether or not you should apply the additional filter however you want.

Thanks,
Ted

Can you provide sample code for doing this?

I am not familiar with the "Page" methods.

Thanks.

Saturday, March 24, 2012

CascadingDropDownlist: How Do I Save the SelectedValue Back To Database

I'm using the AJAX CascadingDropDown extender inside a FormView's InsertItemTemplate.
Question: What is the correct way to save the CascadingDropDown 's selected value back to the database?

I've tried do it by setting the SelectedValue in the CascadingDropDown tag (not the DropDownList) like this:
SelectedValue='<%# Bind("SellerRegionId") %>'

However, when trying to save, this fails with error "Input string was not in a correct format."

I've been able to make it work by setting the Values dictionary in the FormView's ItemInserting() event handler, using the SelectedValue of the DropDownList control (not the extender), as follows:
e.Values["SellerRegionId"] = sellerRegionDropDownList.SelectedValue;

Is this the correct way to do this?

Thanks, in advance, for any help you can give.

Yes the latter should work and in my own opinion personally is more efficient.

CascadingDropDown, SelectedValue in a bound form

Hey folks,

I don't know if it's been addressed, but I couldn't find the solution.

I need to databind selectedValue of a cascading dropdown. Since TargetProperties cannot be databound using <#% #> syntax, I use DataBinding event handler:

 <form id="form1" runat="server"> <div> <atlas:ScriptManager ID="scriptManager" runat="server" EnablePartialRendering="true" /> <asp:FormView ID="frm1" runat="server" DefaultMode="insert"> <InsertItemTemplate> <asp:Button ID="btnToggle" runat="server" OnClick="btnToggle_OnClick" Text="Toggle dropdown panel" /> <asp:Panel ID="pnlDropdown" runat="server" Visible="false"> <asp:DropDownList ID="ddl1" runat="server" /> <atlasToolkit:CascadingDropDown runat="server" ID="cdd1" OnDataBinding="cdd1_DataBinding"> <atlasToolkit:CascadingDropDownProperties TargetControlID="ddl1" ServiceMethod="GetOptions" PromptText="--Select--" Category="Options" /> </atlasToolkit:CascadingDropDown> </asp:Panel> </InsertItemTemplate> </asp:FormView> </div> </form>

With the following codebehind:

protected void btnToggle_OnClick(object sender, EventArgs args) { Panel pnlDropdown = (Panel) ((Control)sender).Parent.FindControl("pnlDropdown" ); pnlDropdown.Visible = !pnlDropdown.Visible; }protected void cdd1_DataBinding(object sender, EventArgs args) { CascadingDropDown cdd1 = (CascadingDropDown)sender; cdd1.TargetProperties[0].SelectedValue ="1"; } [WebMethod]public CascadingDropDownNameValue[] GetOptions(string knownCategoryValues,string category) { CascadingDropDownNameValue[] cddValues =new CascadingDropDownNameValue[] {new CascadingDropDownNameValue("one","1"),new CascadingDropDownNameValue("two","2") };return cddValues; }

The problem exhibits itself only if the CascadingDropDown is originally hidden.

Obviously, this isn't the production code, but it models the behaviour precisly.

Any way to solve it?

Thanks in advance,

ET

Sorry, I forgot to state the actual problem, thespecified SelectedValue is ignored if the dropdown is not visible at the time of binding. Why?

et_td:

Hey folks,

I don't know if it's been addressed, but I couldn't find the solution.

I need to databind selectedValue of a cascading dropdown. Since TargetProperties cannot be databound using <#% #> syntax, I use DataBinding event handler:

 <form id="form1" runat="server"> <div> <atlas:ScriptManager ID="scriptManager" runat="server" EnablePartialRendering="true" /> <asp:FormView ID="frm1" runat="server" DefaultMode="insert"> <InsertItemTemplate> <asp:Button ID="btnToggle" runat="server" OnClick="btnToggle_OnClick" Text="Toggle dropdown panel" /> <asp:Panel ID="pnlDropdown" runat="server" Visible="false"> <asp:DropDownList ID="ddl1" runat="server" /> <atlasToolkit:CascadingDropDown runat="server" ID="cdd1" OnDataBinding="cdd1_DataBinding"> <atlasToolkit:CascadingDropDownProperties TargetControlID="ddl1" ServiceMethod="GetOptions" PromptText="--Select--" Category="Options" /> </atlasToolkit:CascadingDropDown> </asp:Panel> </InsertItemTemplate> </asp:FormView> </div> </form>

With the following codebehind:

protected void btnToggle_OnClick(object sender, EventArgs args) { Panel pnlDropdown = (Panel) ((Control)sender).Parent.FindControl("pnlDropdown" ); pnlDropdown.Visible = !pnlDropdown.Visible; }protected void cdd1_DataBinding(object sender, EventArgs args) { CascadingDropDown cdd1 = (CascadingDropDown)sender; cdd1.TargetProperties[0].SelectedValue ="1"; } [WebMethod]public CascadingDropDownNameValue[] GetOptions(string knownCategoryValues,string category) { CascadingDropDownNameValue[] cddValues =new CascadingDropDownNameValue[] {new CascadingDropDownNameValue("one","1"),new CascadingDropDownNameValue("two","2") };return cddValues; }

The problem exhibits itself only if the CascadingDropDown is originally hidden.

Obviously, this isn't the production code, but it models the behaviour precisly.

Any way to solve it?

Thanks in advance,

ET


As a workaround, I found that setting SelectedValue in an FormView.ItemCreated event handler works.

Cheers,

ET

CascadingDropDown setting SelectedValue programmatically doesnt work

Hi

I have a page which has four dropdowns "linked" together via CascadingDropDown Extenders.

The page works fine, except that I sometimes want the dropdowns to be pre-populated and specific items selected programmatically.

e.g.

1cddlMakes.SelectedValue = cmk.Vehicle.Make.ID2cddlModels.SelectedValue = cmk.Vehicle.Model.ID3cddlTypes.SelectedValue = cmk.Vehicle.Type.ID4cddlEngines.SelectedValue = cmk.Vehicle.Engine.ID

The first 2 dropdowns load and display the correct selected value, but the other two dropdowns SelectedValues don't get set and stay on the "Please Select..." option.

Any ideas?

Using the sample page, I have no issue programmatically setting any of the 3 cascading drop down extenders' selected value. Are you setting the extenders or the controls?
12 CascadingDropDown1.SelectedValue ="Acura";3 CascadingDropDown2.SelectedValue ="Integra";4 CascadingDropDown3.SelectedValue ="Green";

CascadingDropDown SelectedValue Attribute in GridView giving Error

I have a CascadingDropDown inside of an GridView EditItemTemplate. Code is below. I need the SelectedValue of the CascadingDropDown to come from the database when then user Edit's the row. I tried addingSelectedValue='<%# Bind("sentity") %>' but I get this error:

Parser Error Message:The CascadingDropDownProperties control with a two-way databinding to field sentity must have an ID.

Source Error:

Line 67: Line 68: <atlasToolkit:CascadingDropDown ID="CascadingDropDown2" runat="server">Line 69: <atlasToolkit:CascadingDropDownPropertiesLine 70: TargetControlID="ddlEditEntity" Line 71: Category="Entity"

<asp:TemplateFieldHeaderText="Entity">

<EditItemTemplate><asp:DropDownListID="ddlEditEntity"runat="server"CssClass="dropDownList"/><atlasToolkit:CascadingDropDownID="CascadingDropDown2"runat="server"><atlasToolkit:CascadingDropDownPropertiesTargetControlID="ddlEditEntity"Category="Entity"PromptText="<-- Selected an Entity -->"ServicePath="webservices/ws_Timetracking.asmx"ServiceMethod="GetEntitesText"SelectedValue='<%# Bind("sentity") %>'/><atlasToolkit:CascadingDropDownPropertiesTargetControlID="ddlEditProperty"ParentControlID="ddlEditEntity"PromptText="<-- Select a Property -->"ServiceMethod="GetPropsForEntitytext"ServicePath="webservices/ws_Timetracking.asmx"Category="Property"/></atlasToolkit:CascadingDropDown></EditItemTemplate><ItemStyleHorizontalAlign="Left"Width="20%"/><HeaderStyleHorizontalAlign="Left"/><ItemTemplate><asp:LabelID="lblEntity"runat="server"Text='<%# Bind("sentity") %>'></asp:Label></ItemTemplate></asp:TemplateField>As you've noted, the Toolkit controls don't support data binding yet. (Though we have plans to do so soon!) For the time being, I believe you can override your page's OnDataBind method and set the SelectedValue in code. I think Shawn's posted an example of this to the forum. If that's not enough to get you going, reply back and I'll post a sample.

David, I tried setting the selectedValue for the dropdownlist in theGridView1_RowUpdating method, but it seems to not be working.

GridViewRow row = GridView1.Rows[e.RowIndex];
DataKey datakey = GridView1.DataKeys[e.RowIndex];
// Get hmy for updating the database
int hmy =Convert.ToInt32(datakey.Value.ToString());

if (row !=null)
{
DropDownList ddlEditEntity = row.FindControl("ddlEditEntity")asDropDownList;
DropDownList ddlEditProperty = row.FindControl("ddlEditProperty")asDropDownList;
TextBox txtEditDescription = row.FindControl("txtEditDescription")asTextBox;
TextBox txtEditHours = row.FindControl("txtEditHours")asTextBox;ddlEditEntity.SelectedValue = "Chastain Center (8755)"; // this doesn't seem to be workingstring entity = ddlEditEntity.SelectedItem.Value;string property = ddlEditProperty.SelectedItem.Value;string description = txtEditDescription.Text;decimal hours =Convert.ToDecimal(txtEditHours.Text);int retval =Queries.UpdateEntity(hmy, entity, property, description, hours);

GridView1.EditIndex = -1;

GetTimeByUser(ddlYear.SelectedValue +

"/" + ddlMonth.SelectedValue);

}


Well, we added databinding support in the 60731 release of the Toolkit. :) Would you mind trying that approach again with the updated Toolkit? Failing that, let me know and I'll have a look. For real this time. :) Thanks!


When upgrading to the latest do all I need to do is swap out the dll, correct?


Yes, but you'll need to swap out the Microsoft.Web.Atlas.DLL as well (if you're not already using the July CTP).


Thanks David I will try this approach today. One final question. Is it necessary to swap out the Script Library as well? Do you guys update the JavaScript code to reflect changes in the dll?

I swapped out my dll's as followed:

AtlasControlToolkit.dll (version 1.0.60731.0)

Microsoft.AtlasControlExtender.dll (version 1.0.60726.0)

Microsoft.Web.Atlas.dll (version 2.0.50727.60725)

And did the following and still get the error:

The CascadingDropDownProperties control with a two-way databinding to field sentity must have an ID.

<asp:TemplateFieldHeaderText="Entity"><EditItemTemplate><asp:HiddenFieldID="hdnEditEntity"runat="server"Value='<%# Bind("sentity") %>'/><asp:DropDownListID="ddlEditEntity"runat="server"CssClass="dropDownList"/><atlasToolkit:CascadingDropDownID="CascadingDropDown2"runat="server"><atlasToolkit:CascadingDropDownPropertiesTargetControlID="ddlEditEntity"

SelectedValue='<%# Bind("sentity") %>'

Category="Entity"PromptText="<-- Selected an Entity -->"ServicePath="webservices/ws_Timetracking.asmx"ServiceMethod="GetEntitesText"/><atlasToolkit:CascadingDropDownPropertiesTargetControlID="ddlEditProperty"ParentControlID="ddlEditEntity"PromptText="<-- Select a Property -->"ServiceMethod="GetPropsForEntitytext"ServicePath="webservices/ws_Timetracking.asmx"Category="Property"/></atlasToolkit:CascadingDropDown></EditItemTemplate>

joee, I've looked into this for some time and discussed the issue with Shawn as well. Unfortunately for your scenario, we're only able to use one-way databinding (i.e., Eval) in Extender Properties declarations. If you want to handle the CascadingDropDown's SelectedValue that comes back from the client, you'll need to do so in code (at least for the time being - fortunately it shouldn't be very much code!). At a very high level, in order to support two-way databinding, ASP.NET looks for a real Control (hence the error you get about needing an ID) and the Extender Properties objects aren't currently Controls themselves.

Sorry for the trouble; I hope this explanation at least makes things clearer.


Hello

I have a CascadingDropDown in a page and need to set its selectedValue based on the values in the querystring. I tried to use the DataBinding event to set the values, but looks like the event is not being raised.

protected void CascadingDropDown1_DataBinding(object sender, EventArgs e)
{
ddMake.SelectedValue = Request.QueryString["make"];
ddModel.SelectedValue = Request.QueryString["model"];
}

Any ideas?

Thanks for the report! I've just fixed this problem for the next Toolkit release with change 3420 in CodePlex:

Method override ExtenderControlBase.OnDataBinding didn't call base.OnDataBinding, so event handlers hooked up to an extender's .DataBinding event weren't getting fired - this change fixes that problem by calling the base class implementation as it should.

If you're able to use the sources from CodePlex, this should work now. Sorry for the trouble!


Thanks David. I guess change 3431 will address my issue as well. Pardon my ignorance, but how do I work off the source code? Do I just need to build and swap out the Web.Atlas and AtlasControlToolkit.dll?
Yes, just download the sources from CodePlex, extract the files somewhere, build the project, and then use the resulting AtlasControlToolkit.dll instead of the one you were formerly using.

So what is the status now regarding to ways binding, e.g. binding a dropdown's selectedvalue to an item in detailsview ?

CascadingDropDown SelectedValue

Is there a way to set this to a variable such as a Session variable, or must this value be known at compile time? Thanks!

Michael LaneI found the answer indirectly in the FAQ. This works:

CascadingDropDown1.TargetProperties[0].SelectedValue = "1";