Listview link button to another aspx RRS feed

  • Question

  • User-2036877890 posted
    Good day

    I am working on a ListView, where an item selected must navigate to another aspx page with not only the listview information from the previous page but also additional info from the database.

    How it works?
    User to locate customer using either ID, card number or account number.

    When customer has been found in the database, only brief information will be bind to a ListView.

    The ListView has a select command, which when clicked is supposed to keep track of the selected customer and take this information to complete customer details page.

    Please how can I achieve this, I have referred to many resource but it does not yield expected results

    Tuesday, July 24, 2018 6:49 AM

All replies

  • User475983607 posted

    Using command links in ASP.NET data bound controls is a very common and a well documented pattern.   Is there any way that you can post the  source code or at least an example that reproduce the issue?

    It should be as simple as assigning a command argument, usually the unique ID of the records.  Then in the command event, maybe Edit, redirect to the details page and pass any arguments required to fetch the data like a unique id.

    Response.Redirect("the_new_page.aspx?id=" + theCommandArgValue);

    You can also simply add button or link to the ListForm that does the same redirect rather than using a Command Button.

    Tuesday, July 24, 2018 11:50 AM
  • User283571144 posted

    Hi mphomakole,

    According to your description,  I suggest you could use webform’s linkbutton or html’s a mark to navigate to your page.

    You could add query string as additional info for custom id to take to another page.

    More details, you could refer to below codes:

    List view:

    <asp:ListView ID="ListView1" runat="server"  OnItemCommand="ListView1_ItemCommand" DataKeyNames="CustomerID" DataSourceID="SqlDataSource1">
                <ItemTemplate >
                    <tr style="">
                        <td > <a href="DetailsCustomer.aspx?id=<%# Eval("CustomerID") %>"><%# Eval("CustomerID") %></a>
                            <asp:LinkButton ID="LinkButton1" runat="server" PostBackUrl= '<%# "~/ListView/DetailsCustomer.aspx?id="+Eval("CustomerID") %>' Text='<%# Eval("CustomerID") %>'></asp:LinkButton>
                            <asp:Label ID="CustomerIDLabel" runat="server" Text='<%# Eval("CustomerID") %>' />
                            <asp:Label ID="CompanyNameLabel" runat="server" Text='<%# Eval("CompanyName") %>' />
                            <asp:Label ID="ContactNameLabel" runat="server" Text='<%# Eval("ContactName") %>' />
                    <table runat="server">
                        <tr runat="server">
                            <td runat="server">
                                <table id="itemPlaceholderContainer" runat="server" border="0" style="">
                                    <tr runat="server" style="">
                                        <th runat="server">CustomerID</th>
                                        <th runat="server">CompanyName</th>
                                        <th runat="server">ContactName</th>
                                    <tr id="itemPlaceholder" runat="server">
                        <tr runat="server">
                            <td runat="server" style="">
                                <asp:DataPager ID="DataPager1" runat="server">
                                        <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowNextPageButton="False" ShowPreviousPageButton="False" />
                                        <asp:NumericPagerField />
                                        <asp:NextPreviousPagerField ButtonType="Button" ShowLastPageButton="True" ShowNextPageButton="False" ShowPreviousPageButton="False" />
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" SelectCommand="SELECT [CustomerID], [CompanyName], [ContactName] FROM [Customers]"></asp:SqlDataSource>

    Redirect page:

    <form id="form1" runat="server">
            <asp:DetailsView ID="DetailsView2" runat="server" Height="50px" Width="125px"></asp:DetailsView>


    public partial class DetailsCustomer : System.Web.UI.Page
            public string url = ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
            protected void Page_Load(object sender, EventArgs e)
          string customerId=Request["id"];
    //get the details from database through id passed by the previous page
                string sql = "select * from customers where customerId=@id";
                using (SqlDataAdapter adapter = new SqlDataAdapter(sql, url))
                    SqlParameter parameter = new SqlParameter("id", System.Data.SqlDbType.NChar, 5) {Value=customerId };
                    DataTable table = new DataTable();
                    DetailsView2.DataSource = table;


    Best Regards,


    Thursday, July 26, 2018 2:54 AM
  • User-2036877890 posted

    Thanks for the reply Brando ZWZ, I am able to navigate to the other page. However, I am still having the same challenge. While you demonstrated using a detailsview control, I had textboxes. Do you perhaps have any idea what causes the &quot;Incorrect systax near
    '='&quot; error? I was trying to read using data reader but it is not working? Please kindly assist<br>

    40minutes later...Brando I have managed to correct my code after many errors some of which were new to me, I do appreciate your help, you understood my question and guided me in the right direction,thnks again
    Sunday, July 29, 2018 5:32 PM