Advertisement

01.25.2008 at 02:05PM PST, ID: 23112525
[x]
Attachment Details

In an <asp:FormView/> UPDATE City in a table using ZipCode to reference another ZipCode_to_City table

Asked by megnin in Programming for ASP.NET, MS SQL Server, Microsoft Visual Basic.Net

Tags: ASP.Net 2.0, VB, VS 2008, SQL Server 2000

Tell me if this is too difficult to be worth the effort...

Using a FormView on a Web Form to update a SQL Table of Applicants, I need to do something like have a DropDown list of ZipCodes with the current value already selected.
If the City and ZipCode for the Applicant's record needs to be updated, say they moved, then they select their new ZipCode from the DropDown list and the City is automatically updated to match.

I have a table with a 'Zipcode' field and a 'City' field (or I will have one soon)

In addition to the zipcode and city fields in my SQL table there is a field for a CityID and a ZipID which are both two character ID codes for the city and zip.  I hate those codes but they are required for an external database I have to upload my data to at the end of the year.
Anyway, for those codes I have a table with 'Zipcode' and 'ZipID' columns and another table with 'CityName' and 'CityID' columns.

So there's the Applicants table with all the data including LastName, CityName, Zipcode, CityID and ZipID.
There there's the Zipcode-City table, the Zipcode-ZipID table and the CityName-CityID table.

Is it possible to have one <asp:DropDownList/> to select a Zip Code and update the other three fields at the same time?

The answer I'm hopeing for is, "Sure, that's easy".  ;-)
Thanks.

This is my FormView so far.  It works like it is, but has no dropdownlist or any means of keeping the city, zip, cityID and zipID fields synchronized.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Applicant_Verification.aspx.vb" Inherits="Applicant_Verification" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Applicant Verification</title>
<style type="text/css">    
.tab {
position:absolute;
left:9em;
}    
    .style1 { text-align: center; }
</style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
 
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 
            DataSourceID="SqlDataSource2" DataTextField="NameAndSSN" 
            DataValueField="keyApplicantID">
        </asp:DropDownList>
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
            ConnectionString="<%$ ConnectionStrings:SYEP2007ConnectionString1 %>" 
            SelectCommand="SELECT keyApplicantID, LastName + ', ' + FirstName + ', XXX-XX-' + RIGHT (SSN, 4) 
            AS NameAndSSN FROM Applicants where (keyapplicantID &gt; 200800000) ORDER BY LastName">
        </asp:SqlDataSource>
        <br />
        <br />        
        <asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1" 
            BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" 
            CellPadding="3" GridLines="Horizontal" Width="400px" 
            DataKeyNames="keyApplicantID">
            <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
            <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
            <EditItemTemplate>
                ApplicantID:
                <asp:Label ID="keyApplicantIDLabel1" runat="server" Text='<%# Bind("keyApplicantID") %>' CssClass="tab" />
                <br />
                Last Name:
                <asp:TextBox ID="LastNameTextBox" runat="server" Text='<%# Bind("LastName") %>' CssClass="tab"/>
                <br />
                First Name:
                <asp:TextBox ID="FirstNameTextBox" runat="server" Text='<%# Bind("FirstName") %>' CssClass="tab" />
                <br />
                MI:
                <asp:TextBox ID="MITextBox" runat="server" Text='<%# Bind("MI") %>' CssClass="tab" />
                <br />
                DOB:
                <asp:TextBox ID="DOBTextBox" runat="server" Text='<%# Bind("DOB", "{0:d}") %>' CssClass="tab" />
                <br />
                SSN:
                <asp:TextBox ID="SSNTextBox" runat="server" Text='<%# Bind("SSN") %>' CssClass="tab" />
                <br />
                Address:
                <asp:TextBox ID="StreetNameTextBox" runat="server" Text='<%# Bind("StreetName") %>' CssClass="tab" />
                <br />
                CityID:
                <asp:TextBox ID="CityIDTextBox" runat="server" Text='<%# Bind("CityID") %>' 
                    CssClass="tab" ReadOnly="True" />
                <br />
                ZipID:
                <asp:TextBox ID="ZipIDTextBox" runat="server" Text='<%# Bind("ZipID") %>' 
                    CssClass="tab" ReadOnly="True" />
                <br />
                City:
                <asp:TextBox ID="CityNameTextBox" runat="server" Text='<%# Bind("CityName") %>' CssClass="tab" />
                <br />
                Zip:
                <asp:TextBox ID="ZipCodeTextBox" runat="server" Text='<%# Bind("ZipCode") %>' CssClass="tab" />
                <br />
                Telephone:
                <asp:TextBox ID="txtHomeTelephoneTextBox" runat="server" Text='<%# Bind("txtHomeTelephone") %>' CssClass="tab" />
                <br />
                Cellphone:
                <asp:TextBox ID="txtCellphoneTextBox" runat="server" Text='<%# Bind("txtCellphone") %>' CssClass="tab" />
                <br />
                Verified:&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;
                <asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("Verify") %>' />
 
                <br />
                <br />
                <div class="style1">
                <asp:Button ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Save" />&nbsp;
                <asp:Button ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
                </div>
            </EditItemTemplate>
            <InsertItemTemplate>
                LastName:
                <asp:TextBox ID="LastNameTextBox" runat="server" 
                    Text='<%# Bind("LastName") %>' />
                <br />
                FirstName:
                <asp:TextBox ID="FirstNameTextBox" runat="server" 
                    Text='<%# Bind("FirstName") %>' />
                <br />
                MI:
                <asp:TextBox ID="MITextBox" runat="server" Text='<%# Bind("MI") %>' />
                <br />
                DOB:
                <asp:TextBox ID="DOBTextBox" runat="server" Text='<%# Bind("DOB") %>' />
                <br />
                SSN:
                <asp:TextBox ID="SSNTextBox" runat="server" Text='<%# Bind("SSN") %>' />
                <br />
                StreetName:
                <asp:TextBox ID="StreetNameTextBox" runat="server" 
                    Text='<%# Bind("StreetName") %>' />
                <br />
                CityID:
                <asp:TextBox ID="CityIDTextBox" runat="server" Text='<%# Bind("CityID") %>' />
                <br />
                ZipID:
                <asp:TextBox ID="ZipIDTextBox" runat="server" Text='<%# Bind("ZipID") %>' />
                <br />
                CityName:
                <asp:TextBox ID="CityNameTextBox" runat="server" 
                    Text='<%# Bind("CityName") %>' />
                <br />
                ZipCode:
                <asp:TextBox ID="ZipCodeTextBox" runat="server" Text='<%# Bind("ZipCode") %>' />
                <br />
                txtHomeTelephone:
                <asp:TextBox ID="txtHomeTelephoneTextBox" runat="server" 
                    Text='<%# Bind("txtHomeTelephone") %>' />
                <br />
                txtCellphone:
                <asp:TextBox ID="txtCellphoneTextBox" runat="server" 
                    Text='<%# Bind("txtCellphone") %>' />
                <br />
                Verify:
                <asp:TextBox ID="VerifyTextBox" runat="server" Text='<%# Bind("Verify") %>' />
                <br />
                <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" 
                    CommandName="Insert" Text="Insert" />
                &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" 
                    CausesValidation="False" CommandName="Cancel" Text="Cancel" />
            </InsertItemTemplate>
            <ItemTemplate>
                ApplicantID:
                <asp:Label ID="keyApplicantIDLabel1" runat="server" Text='<%# Bind("keyApplicantID") %>' CssClass="tab" />
                <br />
                Last Name:
                <asp:Label ID="LastNameLabel" runat="server" Text='<%# Bind("LastName") %>' CssClass="tab" />
                <br />
                First Name:
                <asp:Label ID="FirstNameLabel" runat="server" Text='<%# Bind("FirstName") %>' CssClass="tab"/>
                <br />
                MI:
                <asp:Label ID="MILabel" runat="server" Text='<%# Bind("MI") %>' CssClass="tab" />
                <br />
                DOB:
                <asp:Label ID="DOBLabel" runat="server" Text='<%# Bind("DOB", "{0:d}") %>' 
                    CssClass="tab" />
                <br />
                SSN:
                <asp:Label ID="SSNLabel" runat="server" Text='<%# Bind("SSN") %>' CssClass="tab" />
                <br />
                Address:
                <asp:Label ID="StreetNameLabel" runat="server" 
                    Text='<%# Bind("StreetName") %>' CssClass="tab" />
                <br />
                CityID:
                <asp:Label ID="CityIDLabel" runat="server" Text='<%# Bind("CityID") %>' CssClass="tab" />
                <br />
                ZipID:
                <asp:Label ID="ZipIDLabel" runat="server" Text='<%# Bind("ZipID") %>' CssClass="tab" />
                <br />
                City:
                <asp:Label ID="CityNameLabel" runat="server" Text='<%# Bind("CityName") %>' CssClass="tab" />
                <br />
                Zip:
                <asp:Label ID="ZipCodeLabel" runat="server" Text='<%# Bind("ZipCode") %>' CssClass="tab" />
                <br />
                Telephone:
                <asp:Label ID="txtHomeTelephoneLabel" runat="server" Text='<%# Bind("txtHomeTelephone") %>' CssClass="tab" />
                <br />
                Cellphone:
                <asp:Label ID="txtCellphoneLabel" runat="server" Text='<%# Bind("txtCellphone") %>' CssClass="tab" />
                <br />
                Verified:
                <asp:Label ID="VerifyLabel" runat="server" Text='<%# Bind("Verify") %>' CssClass="tab" />
                <br />
                <br />
                <div class="style1">
                <asp:Button ID="editbutton" runat="server" CausesValidation="True" CommandName="Edit" Text="Edit" />
                </div>
            </ItemTemplate>
            <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
            <FooterTemplate>
                <div class="style1">
                WorkForce One
                </div>
            </FooterTemplate>
            <HeaderStyle BackColor="#006D75" Font-Bold="True" ForeColor="#F7F7F7" />
            <HeaderTemplate>
                <div class="style1">
                    Summer Youth Employment Program 2008 Verification
                </div>
            </HeaderTemplate>
            <EditRowStyle BackColor="#8C004C" Font-Bold="True" ForeColor="#F7F7F7" />
        </asp:FormView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:SYEP2007ConnectionString1 %>" 
            DeleteCommand="DELETE FROM [Applicants] WHERE [keyApplicantID] = @original_keyApplicantID AND [LastName] = @original_LastName AND [FirstName] = @original_FirstName AND [MI] = @original_MI AND [SSN] = @original_SSN AND [StreetName] = @original_StreetName AND [CityID] = @original_CityID AND [ZipID] = @original_ZipID AND [DOB] = @original_DOB AND [txtHomeTelephone] = @original_txtHomeTelephone AND [txtCellphone] = @original_txtCellphone AND [CityName] = @original_CityName AND [ZipCode] = @original_ZipCode AND [Verify] = @original_Verify" 
            InsertCommand="INSERT INTO [Applicants] ([LastName], [FirstName], [MI], [SSN], [StreetName], [CityID], [ZipID], [DOB], [txtHomeTelephone], [txtCellphone], [CityName], [ZipCode], [Verify]) VALUES (@LastName, @FirstName, @MI, @SSN, @StreetName, @CityID, @ZipID, @DOB, @txtHomeTelephone, @txtCellphone, @CityName, @ZipCode, @Verify)" 
            SelectCommand="SELECT [keyApplicantID], [LastName], [FirstName], [MI], [SSN], [StreetName], [CityID], [ZipID], [DOB], [txtHomeTelephone], [txtCellphone], [CityName], [ZipCode], [Verify] FROM [Applicants] WHERE ([keyApplicantID] = @keyApplicantID)" 
            UpdateCommand="UPDATE Applicants SET LastName = @LastName, FirstName = @FirstName, MI = @MI, SSN = @SSN, StreetName = @StreetName, CityID = @CityID, ZipID = @ZipID, DOB = @DOB, txtHomeTelephone = @txtHomeTelephone, txtCellphone = @txtCellphone, CityName = @CityName, ZipCode = @ZipCode, Verify = @Verify
                           WHERE (keyApplicantID = @keyApplicantID)">
            <SelectParameters>
                <asp:ControlParameter ControlID="DropDownList1" Name="keyApplicantID" PropertyName="SelectedValue" Type="Int32" />
            </SelectParameters>
            <DeleteParameters>
                <asp:Parameter Name="original_keyApplicantID" Type="Int32" />
                <asp:Parameter Name="original_LastName" Type="String" />
                <asp:Parameter Name="original_FirstName" Type="String" />
                <asp:Parameter Name="original_MI" Type="String" />
                <asp:Parameter Name="original_SSN" Type="String" />
                <asp:Parameter Name="original_StreetName" Type="String" />
                <asp:Parameter Name="original_CityID" Type="Int32" />
                <asp:Parameter Name="original_ZipID" Type="Int32" />
                <asp:Parameter Name="original_DOB" Type="DateTime" />
                <asp:Parameter Name="original_txtHomeTelephone" Type="String" />
                <asp:Parameter Name="original_txtCellphone" Type="String" />
                <asp:Parameter Name="original_CityName" Type="String" />
                <asp:Parameter Name="original_ZipCode" Type="Int32" />
                <asp:Parameter Name="original_Verify" Type="String" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="LastName" Type="String" />
                <asp:Parameter Name="FirstName" Type="String" />
                <asp:Parameter Name="MI" Type="String" />
                <asp:Parameter Name="SSN" Type="String" />
                <asp:Parameter Name="StreetName" Type="String" />
                <asp:Parameter Name="CityID" Type="Int32" />
                <asp:Parameter Name="ZipID" Type="Int32" />
                <asp:Parameter Name="DOB" Type="DateTime" />
                <asp:Parameter Name="txtHomeTelephone" Type="String" />
                <asp:Parameter Name="txtCellphone" Type="String" />
                <asp:Parameter Name="CityName" Type="String" />
                <asp:Parameter Name="ZipCode" Type="Int32" />
                <asp:Parameter Name="Verify" Type="String" />
                <asp:Parameter Name="keyApplicantID" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="LastName" Type="String" />
                <asp:Parameter Name="FirstName" Type="String" />
                <asp:Parameter Name="MI" Type="String" />
                <asp:Parameter Name="SSN" Type="String" />
                <asp:Parameter Name="StreetName" Type="String" />
                <asp:Parameter Name="CityID" Type="Int32" />
                <asp:Parameter Name="ZipID" Type="Int32" />
                <asp:Parameter Name="DOB" Type="DateTime" />
                <asp:Parameter Name="txtHomeTelephone" Type="String" />
                <asp:Parameter Name="txtCellphone" Type="String" />
                <asp:Parameter Name="CityName" Type="String" />
                <asp:Parameter Name="ZipCode" Type="Int32" />
                <asp:Parameter Name="Verify" Type="String" />
            </InsertParameters>
        </asp:SqlDataSource>
        <br />
    </div>
    </form>
</body>
</html>
[+][-]01.26.2008 at 02:01PM PST, ID: 20751479

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]01.27.2008 at 11:05AM PST, ID: 20754686

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.28.2008 at 11:45AM PST, ID: 20762177

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.28.2008 at 12:45PM PST, ID: 20762710

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Programming for ASP.NET, MS SQL Server, Microsoft Visual Basic.Net
Tags: ASP.Net 2.0, VB, VS 2008, SQL Server 2000
Sign Up Now!
Solution Provided By: megnin
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628