Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8920091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:10:46+00:00 2026-06-15T06:10:46+00:00

I have a form that lists customers pulled from a db. The form also

  • 0

I have a form that lists customers pulled from a db. The form also consists of edit and delete buttons in order to update an existing customer’s record. I am able to pull back all the table data for the customers on the first page. However, when I click the “Edit” button next to a customer it does not bring back any data but just brings back a blank form. I am referencing the CustomerID in the “Edit” hyperlink with a NavigateURL link. I have read and read and am getting confused about how to do this. Can anyone see what I may be doing wrong? Getting very frustrated. Please help.

<div>
    <h2>Customer Listing</h2>
    <br />
</div>

<p style="text-align:center">
    <asp:Button ID="btnCustomer" class="button" runat="server" Text="Add New Customer" onclick="btnCustomer_Click" />
</p>


<asp:ListView ID="lv" runat="server" 
    onselectedindexchanged="lv_SelectedIndexChanged">
<LayoutTemplate>
  <table width="110%" class="TableListing">
  <tbody>
    <thead>
    <th width="150">Customer Name</th>
      <th width="150">Email</th>
      <th width="150">City</th>
      <th width="40">State</th>
      <th width="110">Phone</th>
      <th width="80">Modify</th>
    </thead>
    <tr id="itemPlaceholder" runat="server"></tr>
     </tbody>
    </table>  

    <asp:DataPager ID="ItemDataPager" runat="server" PageSize="20">
        <Fields>
            <asp:NumericPagerField ButtonCount="5" />
        </Fields>
    </asp:DataPager>

</LayoutTemplate>

<ItemTemplate>
    <tr>
     <td><%# Eval ("LastName") %>, <%# Eval ("FirstName") %></td>
     <td><%# Eval ("Email") %></td>
     <td><%# Eval ("City") %></td>
     <td><%# Eval ("State") %></td>
     <td><%# Eval ("Phone") %></td>
     <td>
        <asp:HyperLink ID="lnkEdit" runat="server" NavigateUrl='<%# "CustomerEdit.aspx?ID=" + Eval("CustomerID") + Request.QueryString["LastName"] + Eval("LastName") %>' Text="Edit" />
    </td>
    </tr>
</ItemTemplate>

I then redirect to the CustomerEdit page:

    protected void Page_Load(object sender, EventArgs e)
    {
        this.Master.HighlightNavItem("Customers");

        int CustomerID = 0;


        //Declare the connection object
        SqlConnection Conn = new SqlConnection();
        Conn.ConnectionString = ConfigurationManager.ConnectionStrings["MyDatabase"].ConnectionString;

        //Connect to the db
        Conn.Open();

    //Define query
        string sql = "SELECT * FROM Customer where CustomerID=@CustomerID";

    //Declare the Command
    SqlCommand cmd = new SqlCommand(sql, Conn);

    //Add the parameters needed for the SQL query
    //cmd.Parameters.AddWithValue("@LastName", LastName);

    //Declare the DataReader
    SqlDataReader dr = null;

    //Fill the DataReader
    dr = cmd.ExecuteReader();

    //Get the data
    if (dr.Read() == false)
    {
        //No Records
        dr.Close();
        Conn.Close();
        return;
    }

    txtFirstName.Text = dr["FirstName"].ToString();
    txtLastName.Text = dr["LastName"].ToString();

    dr.Close();
    Conn.Close();


    }


    protected void btnCancel_Click1(object sender, EventArgs e)
    {
        Response.Redirect("Customers.aspx");
    }

    protected void btnUpdate_Click(object sender, EventArgs e)
    {

        //Declare the connection object
        SqlConnection Conn = new SqlConnection();
        Conn.ConnectionString = ConfigurationManager.ConnectionStrings["MyDatabase"].ConnectionString;

        //Connect to the db
        Conn.Open();

        //Define query
        string sql = "INSERT INTO Customer (FirstName, LastName, Email, Password, Address1, Address2, City, State, Zip, Phone, Fax) VALUES (@FirstName, @LastName, @Email, @Password, @Address1, @Address2, @City, @State, @Zip, @Phone, @Fax)";
        //sql = "INSERT INTO xSample(Region,RepName,...) VALUES(@Region,@RepName,...)


        //Declare the Command
        SqlCommand cmd = new SqlCommand(sql, Conn);

        //Add the parameters needed for the SQL query
        cmd.Parameters.AddWithValue("@FirstName", txtFirstName.Text);
        cmd.Parameters.AddWithValue("@LastName", txtLastName.Text);
        cmd.Parameters.AddWithValue("@Email", txtEmail1.Text);
        cmd.Parameters.AddWithValue("@Password", txtPassword1.Text);
        cmd.Parameters.AddWithValue("@Address1", txtAddress1.Text);
        cmd.Parameters.AddWithValue("@Address2", txtAddress2.Text);
        cmd.Parameters.AddWithValue("@City", txtCity.Text);
        cmd.Parameters.AddWithValue("@State", txtState.Text);
        cmd.Parameters.AddWithValue("@Zip", txtZip.Text);
        cmd.Parameters.AddWithValue("@Phone", txtPhone.Text);
        cmd.Parameters.AddWithValue("@Fax", txtFax.Text);

        //Execute the query
        int NumRows = 0;
        NumRows = cmd.ExecuteNonQuery();

        Conn.Close();

        lblUpdate.Text = "Updated " + NumRows.ToString() + " record";

    }

}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T06:10:48+00:00Added an answer on June 15, 2026 at 6:10 am

    In your page_load of the custmeredit.aspx

    replace this:

    int CustomerID = 0;
    

    with:

    int CustomerID = Int32.Parse(Request.QueryString["ID"]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form with a list that shows information from a database. I
I have a PHP page that I'm using JavaScript with to update dropdown lists
I have this problem, in a form I have a list of customers that
I have an Order model. Customers get a handful of consumer-friendly views that let
I have a form that returns me a List of FlatSessie objects in my
Say I have a form that contains a drop-down list populated by values stored
I have created a list form that gets attached to a main form in
I have a HTML form that accepts a comma separated list of tags, which
I currently have form that checks if a user has unsubmitted changes when they
I have a form that I'm submitting through AJAX. The form includes many fields,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.