Portal Engine Questions on portal engine and web parts.
Version 4.x > Portal Engine > Can I make the State field on a BizForm dynamic, based on the country? View modes: 
User avatar
Member
Member
john-wakefly - 8/21/2009 8:01:57 AM
   
Can I make the State field on a BizForm dynamic, based on the country?
I have a state and country fields on a BizForm.

Is there anyway for me to make the State field dynamic, based on what Country is selected?

Thanks in advance!

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 8/25/2009 4:01:49 AM
   
RE:Can I make the State field on a BizForm dynamic, based on the country?
Hi John,

You could use out built-in Country selector form control. It works in the way you described. You would add a new field of type: Country selector in CMSDesk -> Tools -> BizForms


Best regards,
Helena Grulichova

User avatar
Member
Member
john-wakefly - 8/25/2009 7:44:13 AM
   
RE:Can I make the State field on a BizForm dynamic, based on the country?
Hi Helena,
Thank you for the reply, but I'm not sure how that would help me. I need the country dropdown to determine what shows for the state field. The state field should be dropdowns for USA and Canada, and text fields for all others. Thanks,

-John

User avatar
Kentico Support
Kentico Support
kentico_radekm - 9/17/2009 1:36:13 AM
   
RE:Can I make the State field on a BizForm dynamic, based on the country?
Hello.

For this purpose, you could use your own custom form control (http://devnet.kentico.com/docs/devguide/developing_form_controls.htm). You can use two drop-down menus, fill them with appropriate value e.g. from text array and ensure requested functionality. You can see example here:

Definition of two drop-down menus:

<asp:DropDownList ID=”DropDownList1” Runat=”server”
OnSelectedIndexChanged=”DropDownList1_SelectedIndexChanged”
AutoPostBack=”true”>
<asp:ListItem>State 1</asp:ListItem>
<asp:ListItem>State 2</asp:ListItem>
<asp:ListItem>State 3</asp:ListItem>
</asp:DropDownList>

<asp:DropDownList ID=”DropDownList2” Runat=”server” Visible=”false”>
</asp:DropDownList>
<asp:Button ID=”Button1” Runat=”server” Text=”Select Options”
OnClick=”Button1_Click” />

C# code:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string[] Country1Array = new string[4] {“Option 1”, “Option 2”, “Option 3”, “Option 4”};
string[] Country2Array = new string[3] {“Option 1”, “Option 2”,
“Option 3”};
string[] Country3Array = new string[3] {“Option 1”, “Option 2”, “Option 3”};
if (DropDownList1.SelectedValue == “State 1”) {
DropDownList2.DataSource = Country1Array; }
else if (DropDownList1.SelectedValue == “State 2”) {
DropDownList2.DataSource = Country2Array; }
else {
DropDownList2.DataSource = Country3Array;
}
DropDownList2.DataBind();
DropDownList2.Visible = true;
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write(“You selected <b>” +
DropDownList1.SelectedValue.ToString() + “: “ +
DropDownList2.SelectedValue.ToString() + “</b>”);
}

Best Regards,
Radek Macalik