Jump to content

Appending the primary key of the selected record to the url on the first page

- - - - -

  • Please log in to reply
1 reply to this topic

#1
Ratphink120

Ratphink120

    Newbie

  • Members
  • Pip
  • 1 posts
I have a dropdownlist with a hyperlink control to another page. I can't figure out how to append the primary key of the selected record in the dropdownlist to the url of the page. I need to do this in order to display the corresponding selected information on a formview. I just can't figure out how to link the two pages. I was told to use a querystringparameter object but I don't know what code to put where.

Here is what I have inFirstPage.aspx...

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:spring11u05ConnectionString %>"
SelectCommand="SELECT * FROM [Customer]"></asp:SqlDataSource>
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource1" DataTextField="Username"
DataValueField="Customer_ID" DataMember="DefaultView">
</asp:DropDownList>

<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />

</div>


<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/SecondPage.aspx">Click here to see the customer's information</asp:HyperLink>

And here is the SecondPage.aspx (the page I'm trying to send the value of Customer_ID to the Formview)

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:spring11u05ConnectionString %>"
SelectCommand="SELECT * FROM [Customer]"
InsertCommand="INSERT into Customer (Customer_ID,Username,Password,First_Name,Last_Name,Shipping_address,Phone,Email,Website) VALUES (@Customer_ID,@Username,@Password,@First_Name,@Last_Name,@Shipping_address,@Phone,@Email,@Website)"
UpdateCommand="UPDATE Customer SET First_Name=@First_Name,Last_Name=@Last_Name,Shipping_address=@Shipping_address,Phone=@Phone,Email=@Email,Username=@Username,Password=@Password,Website=@Website WHERE Customer_ID=Customer_ID"
DeleteCommand="DELETE FROM Customer WHERE (Customer_ID = @Customer_ID)">
<DeleteParameters>
<asp:Parameter Name="Customer_ID" />
</DeleteParameters>
</asp:SqlDataSource>
<asp:FormView
ID="FormView1"
runat="server"
DataSourceID="SqlDataSource1"
DataKeyNames="Customer_ID" AllowPaging="True" >
<ItemTemplate>
<h1><%# Eval("Username") %></h1>
<b> Customer ID:</b>
<%# Eval("Customer_ID") %>
<br />
<b> First Name:</b>
<%# Eval("First_Name") %>
<br />
<b> Last Name:</b>
<%# Eval("Last_Name") %>
<br />
<b> Shipping Address:</b>
<%# Eval("Shipping_address") %>
<br />
<b> Phone:</b>
<%# Eval("Phone") %>
<br />
<b> Email:</b>
<%# Eval("Email") %>
<br />
<b> Website:</b>
<%# Eval("Website") %>
<hr />
<asp:LinkButton
id="lnkNew"
Text="Click Here to Insert a New Customer"
Commandname="New"
Runat="server" />
<asp:LinkButton
id="lnkEdit"
Text="Click Here to Edit the Customer"
CommandName="Edit"
OnClientClick="return confirm('Are you sure?');"
Runat="server" />
<asp:LinkButton
id="lnkDelete"
Text="Click Here to Delete the Customer"
CommandName="Delete"
OnClientClick="return confirm('Are you sure?');"
Runat="server" />
</ItemTemplate>
<EditRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
<InsertItemTemplate>
<asp:Label
id="lblID"
Text="Customer ID:"
AssociatedControlID="txtID"
Runat="server" />
<br />
<asp:TextBox
id="txtID"
Text='<%# Bind("Customer_ID") %>'
Runat="server" />
<asp:RequiredFieldValidator
ID="RequiredFieldValidator1"
runat="server"
ErrorMessage="ID is Required" ControlToValidate="txtID">ID is Required</asp:RequiredFieldValidator>
<asp:CompareValidator ID="CompareValidator1" runat="server"
ErrorMessage="ID be type int"
ControlToValidate="txtID" Type="Integer" Operator="DataTypeCheck">Must be type int</asp:CompareValidator>
<br /><br />
<asp:Label
id="LabelUserName"
Text="Username:"
AssociatedControlID="txtUserName"
Runat="server" />
<br />
<asp:TextBox
id="txtUserName"
Text='<%# Bind("Username") %>'
Runat="server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ErrorMessage="Username is Required" ControlToValidate="txtUserName">Username is Required</asp:RequiredFieldValidator>
<br /><br />
<asp:Label
id="LabelPass"
Text="Password:"
AssociatedControlID="txtPass"
Runat="server" />
<br />
<asp:TextBox
id="txtPass"
Text='<%# Bind("Password") %>'
Runat="server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ErrorMessage="Password is Required" ControlToValidate="txtPass">Password is Required</asp:RequiredFieldValidator>
<br /><br />
<asp:Label
id="lblFirst"
Text="First Name:"
AssociatedControlID="txtFirst"
Runat="server" />
<br />
<asp:TextBox
id="txtFirst"
Text='<%# Bind("First_Name") %>'
Runat="server" />
<asp:CompareValidator ID="CompareValidator4" runat="server"
ErrorMessage="First Name must be type string" ControlToValidate="txtFirst"
Operator="DataTypeCheck" ViewStateMode="Enabled">Must be type string</asp:CompareValidator>
<br /><br />
<asp:Label
id="LabelLast"
Text="Last Name:"
AssociatedControlID="txtLast"
Runat="server" />
<br />
<asp:TextBox
id="txtLast"
Text='<%# Bind("Last_Name") %>'
Runat="server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ErrorMessage="Last Name is Required" ControlToValidate="txtLast">Last Name is Required</asp:RequiredFieldValidator>
<asp:CompareValidator ID="CompareValidator5" runat="server"
ErrorMessage="Last name must be type string" ControlToValidate="txtLast"
Operator="DataTypeCheck">Must be type string</asp:CompareValidator>
<br /><br />
<asp:Label
id="LabelAddress"
Text="Shipping Address:"
AssociatedControlID="txtAddress"
Runat="server" />
<br />
<asp:TextBox
id="txtAddress"
Text='<%# Bind("Shipping_address") %>'
Runat="server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
ErrorMessage="Address is Required" ControlToValidate="txtAddress">Address is Required</asp:RequiredFieldValidator>
<br /><br />
<asp:Label
id="LabelPhone"
Text="Phone Number:"
AssociatedControlID="txtPhone"
Runat="server" />
<br />
<asp:TextBox
id="txtPhone"
Text='<%# Bind("Phone") %>'
Runat="server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server"
ErrorMessage="Phone Number is Required" ControlToValidate="txtPhone">Phone Number is Required</asp:RequiredFieldValidator>
<asp:CompareValidator ID="CompareValidator7" runat="server"
ErrorMessage="Phone Number must be type int" ControlToValidate="txtPhone"
Type="Double" Operator="DataTypeCheck">Must be type int</asp:CompareValidator>
<br /><br />
<asp:Label
id="LabelEmail"
Text="Email Address:"
AssociatedControlID="txtEmail"
Runat="server" />
<br />
<asp:TextBox
id="txtEmail"
Text='<%# Bind("Email") %>'
Runat="server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server"
ErrorMessage="Email Address is Required" ControlToValidate="txtEmail">Email Address is Required</asp:RequiredFieldValidator>
<br /><br />
<asp:Label
id="LabelWeb"
Text="Website:"
AssociatedControlID="txtWeb"
Runat="server" />
<br />
<asp:TextBox
id="txtWeb"
Text='<%# Bind("Website") %>'
Runat="server" />
<br /><br />
<asp:LinkButton
id="lnkInsert"
Text="Insert Customer"
CommandName="Insert"
Runat="server" />
<asp:LinkButton
id="lnkCancel"
Text="Cancel Customer"
CommandName="Cancel"
Runat="server" />
</InsertItemTemplate>
<EditItemTemplate>

<asp:Label
id="LabelID"
Text="ID"
AssociatedControlID="txtID"
Runat="server" />
<br />
<asp:TextBox
id="txtID"
Text='<%# Bind("Customer_ID") %>'
Runat="server" Visible="True" ReadOnly="True" />
<br /><br />
<asp:Label
id="LabelUserName"
Text="Username:"
AssociatedControlID="txtUserName"
Runat="server" />
<br />
<asp:TextBox
id="txtUserName"
Text='<%# Bind("Username") %>'
Runat="server" />
<br /><br />
<asp:Label
id="LabelPass"
Text="Password:"
AssociatedControlID="txtPass"
Runat="server" />
<br />
<asp:TextBox
id="txtPass"
Text='<%# Bind("Password") %>'
Runat="server" />
<br /><br />
<asp:Label
id="lblFirst"
Text="First Name:"
AssociatedControlID="txtFirst"
Runat="server" />
<br />
<asp:TextBox
id="txtFirst"
Text='<%# Bind("First_Name") %>'
Runat="server" />
<br /><br />
<asp:Label
id="LabelLast"
Text="Last Name:"
AssociatedControlID="txtLast"
Runat="server" />
<br />
<asp:TextBox
id="txtLast"
Text='<%# Bind("Last_Name") %>'
Runat="server" />
<br /><br />
<asp:Label
id="LabelAddress"
Text="Shipping Address:"
AssociatedControlID="txtAddress"
Runat="server" />
<br />
<asp:TextBox
id="txtAddress"
Text='<%# Bind("Shipping_address") %>'
Runat="server" />
<br /><br />
<asp:Label
id="LabelPhone"
Text="Phone Number:"
AssociatedControlID="txtPhone"
Runat="server" />
<br />
<asp:TextBox
id="txtPhone"
Text='<%# Bind("Phone") %>'
Runat="server" />
<br /><br />
<asp:Label
id="LabelEmail"
Text="Email Address:"
AssociatedControlID="txtEmail"
Runat="server" />
<br />
<asp:TextBox
id="txtEmail"
Text='<%# Bind("Email") %>'
Runat="server" />
<br /><br />
<asp:Label
id="LabelWeb"
Text="Website:"
AssociatedControlID="txtWeb"
Runat="server" />
<br />
<asp:TextBox
id="txtWeb"
Text='<%# Bind("Website") %>'
Runat="server" />
<br /><br />
<asp:LinkButton
id="lnkUpdate"
Text="Confirm Customer Update"
CommandName="Update"
Runat="server" />
<asp:LinkButton
id="lnkCancel"
Text="Cancel Customer Update"
CommandName="Cancel"
Runat="server" />
</EditItemTemplate>
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
</asp:FormView>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" />


Any help would be greatly appreciated! :w00t:

#2
sam_coder

sam_coder

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 372 posts
I'd love to help ya,
can you edit your post and stick it in a code block? I think that would get rid of all the smily faces... =)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users