using the below code..
I select an item in the City combo and it does a SetFocus to the Zip combo. It automatically puts the first zipcode in the ZipCode.Text field. I can't seem to get this to work no matter what I've tried..It always has the previous ZipCode selection in the list
Based on a City selection I'd like to auto select a Zip if only one is available and then auto select the County and State. But I also have to allow custom text in City and Zip for Out Of State entries..
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:SqlDataSource ID="SqlradCity" runat="server"
ConnectionString="<%$ ConnectionStrings:db_DELJISDataConnectionString %>"
SelectCommand="SELECT DISTINCT [Description] FROM [Zip_Codes] ORDER BY Description ASC">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlradZipMail" runat="server"
ConnectionString="<%$ ConnectionStrings:db_DELJISDataConnectionString %>"
SelectCommand="SELECT [Code],[County] FROM [Zip_Codes] WHERE ([Description] = @Description) ORDER BY Code ASC">
<SelectParameters>
<asp:ControlParameter ControlID="radCityMail" Name="Description"
PropertyName="Text" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<table>
<tr>
<td>
City:
<telerik:RadComboBox id="radCityMail" runat="server" CausesValidation="False"
Skin="Outlook" AllowCustomText="True" Height="150px" MarkFirstMatch="True"
MaxLength="18" AutoPostBack="true" OnTextChanged="radCity_TextChanged"
DataSourceID="SqlradCity" DataTextField="Description" CollapseAnimation-Type="None" />
</td>
<td>
Zip Code:
<telerik:RadComboBox id="radZipCodeMail" runat="server" MaxLength="9"
Skin="Outlook" AllowCustomText="True" Height="150px" Width="70px" EnableLoadOnDemand="true"
CausesValidation="False" AutoPostBack="true" OnTextChanged="radZipCode_TextChanged"
DataSourceID="SqlradZipMail" DataTextField="Code" DataValueField="County" CollapseAnimation-Type="None" />
</td>
<td>
County:
<asp:DropDownList ID="ddlCountyMail" runat="server">
<asp:ListItem />
<asp:ListItem Value="N" Text="New Castle County" />
<asp:ListItem Value="K" Text="Kent County" />
<asp:ListItem Value="S" Text="Sussex County" />
<asp:ListItem Value="O" Text="Other" />
</asp:DropDownList>
</td>
<td>
State:
<asp:DropDownList ID="ddlStateMail" runat="server" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
And Code Behind
#region City/ZIP Events
/* Handles ALL rad city textchanged events */
protected void radCity_TextChanged(object sender, EventArgs e) {
Telerik.Web.UI.RadComboBox zip = null, city = null;
if(sender.Equals(radCityMail)) { // mail address
zip = radZipCodeMail; city = radCityMail;
}
if(sender.Equals(radCityPhysical)) { // physical address
zip = radZipCodePhysical; city = radCityPhysical;
}
if(city.SelectedIndex > -1) { // in-state
zip.AllowCustomText = false;
} else { // out of state
zip.AllowCustomText = true;
}
SetFocus(zip);
radZipCode_TextChanged(zip, null);
}
/* Handles ALL rad zip code textchanged events */
protected void radZipCode_TextChanged(object sender, EventArgs e) {
Telerik.Web.UI.RadComboBox zip = null, city = null;
DropDownList county = null, state = null;
if(sender.Equals(radZipCodeMail)) { // mail address
zip = radZipCodeMail; city = radCityMail;
county = ddlCountyMail; state = ddlStateMail;
}
if(sender.Equals(radZipCodePhysical)) { // physical address
zip = radZipCodePhysical; city = radCityPhysical;
county = ddlCountyPhysical; state = ddlStatePhysical;
}
if(city.SelectedItem != null) { // in-state
state.ClearSelection(); state.SelectedIndex = -1;
county.ClearSelection(); county.SelectedIndex = -1;
county.Items.FindByValue("O").Enabled = false;
state.Items.FindByValue("DE").Enabled = true;
state.Items.FindByValue("DE").Selected = true;
state.Enabled = false; county.Enabled = true;
county.Items.FindByValue(zip.SelectedValue).Selected = true;
SetFocus(county);
} else { // out of state
state.ClearSelection(); state.SelectedIndex = -1;
county.ClearSelection(); county.SelectedIndex = -1;
state.Items.FindByValue("DE").Enabled = false; state.Enabled = true;
county.Items.FindByValue("O").Enabled = true;
county.Items.FindByValue("O").Selected = true; county.Enabled = false;
SetFocus(state);
}
}
#endregion
I select an item in the City combo and it does a SetFocus to the Zip combo. It automatically puts the first zipcode in the ZipCode.Text field. I can't seem to get this to work no matter what I've tried..It always has the previous ZipCode selection in the list
Based on a City selection I'd like to auto select a Zip if only one is available and then auto select the County and State. But I also have to allow custom text in City and Zip for Out Of State entries..
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:SqlDataSource ID="SqlradCity" runat="server"
ConnectionString="<%$ ConnectionStrings:db_DELJISDataConnectionString %>"
SelectCommand="SELECT DISTINCT [Description] FROM [Zip_Codes] ORDER BY Description ASC">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlradZipMail" runat="server"
ConnectionString="<%$ ConnectionStrings:db_DELJISDataConnectionString %>"
SelectCommand="SELECT [Code],[County] FROM [Zip_Codes] WHERE ([Description] = @Description) ORDER BY Code ASC">
<SelectParameters>
<asp:ControlParameter ControlID="radCityMail" Name="Description"
PropertyName="Text" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<table>
<tr>
<td>
City:
<telerik:RadComboBox id="radCityMail" runat="server" CausesValidation="False"
Skin="Outlook" AllowCustomText="True" Height="150px" MarkFirstMatch="True"
MaxLength="18" AutoPostBack="true" OnTextChanged="radCity_TextChanged"
DataSourceID="SqlradCity" DataTextField="Description" CollapseAnimation-Type="None" />
</td>
<td>
Zip Code:
<telerik:RadComboBox id="radZipCodeMail" runat="server" MaxLength="9"
Skin="Outlook" AllowCustomText="True" Height="150px" Width="70px" EnableLoadOnDemand="true"
CausesValidation="False" AutoPostBack="true" OnTextChanged="radZipCode_TextChanged"
DataSourceID="SqlradZipMail" DataTextField="Code" DataValueField="County" CollapseAnimation-Type="None" />
</td>
<td>
County:
<asp:DropDownList ID="ddlCountyMail" runat="server">
<asp:ListItem />
<asp:ListItem Value="N" Text="New Castle County" />
<asp:ListItem Value="K" Text="Kent County" />
<asp:ListItem Value="S" Text="Sussex County" />
<asp:ListItem Value="O" Text="Other" />
</asp:DropDownList>
</td>
<td>
State:
<asp:DropDownList ID="ddlStateMail" runat="server" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
And Code Behind
#region City/ZIP Events
/* Handles ALL rad city textchanged events */
protected void radCity_TextChanged(object sender, EventArgs e) {
Telerik.Web.UI.RadComboBox zip = null, city = null;
if(sender.Equals(radCityMail)) { // mail address
zip = radZipCodeMail; city = radCityMail;
}
if(sender.Equals(radCityPhysical)) { // physical address
zip = radZipCodePhysical; city = radCityPhysical;
}
if(city.SelectedIndex > -1) { // in-state
zip.AllowCustomText = false;
} else { // out of state
zip.AllowCustomText = true;
}
SetFocus(zip);
radZipCode_TextChanged(zip, null);
}
/* Handles ALL rad zip code textchanged events */
protected void radZipCode_TextChanged(object sender, EventArgs e) {
Telerik.Web.UI.RadComboBox zip = null, city = null;
DropDownList county = null, state = null;
if(sender.Equals(radZipCodeMail)) { // mail address
zip = radZipCodeMail; city = radCityMail;
county = ddlCountyMail; state = ddlStateMail;
}
if(sender.Equals(radZipCodePhysical)) { // physical address
zip = radZipCodePhysical; city = radCityPhysical;
county = ddlCountyPhysical; state = ddlStatePhysical;
}
if(city.SelectedItem != null) { // in-state
state.ClearSelection(); state.SelectedIndex = -1;
county.ClearSelection(); county.SelectedIndex = -1;
county.Items.FindByValue("O").Enabled = false;
state.Items.FindByValue("DE").Enabled = true;
state.Items.FindByValue("DE").Selected = true;
state.Enabled = false; county.Enabled = true;
county.Items.FindByValue(zip.SelectedValue).Selected = true;
SetFocus(county);
} else { // out of state
state.ClearSelection(); state.SelectedIndex = -1;
county.ClearSelection(); county.SelectedIndex = -1;
state.Items.FindByValue("DE").Enabled = false; state.Enabled = true;
county.Items.FindByValue("O").Enabled = true;
county.Items.FindByValue("O").Selected = true; county.Enabled = false;
SetFocus(state);
}
}
#endregion