I have a ASP.NET WebForms project, I'm using GridView to see data from a database.

I'm seeing my data in the gridview and its working, now my next step is how can I turn that data into a list I can use so instead of seeing it all at once, a user can see Step 1 then click next and see Step 2 etc and it stops at the end? Ex Step 14

How the data looks on the website in GridView:

StepNumber  Idx_StepId
    1          127
    2          128
    3          129
    4          130
    5          131
    6          132
    7          133
    8          134
    9          135
    10         136
    11         137
    12         138
    13         139
    14         140

C# Class file for database query and connection:

namespace WebForms.Classes
{
    public class ProductOps
    {
        public DataTable ProdStepJoin(string id)
        {
            try
            {
                string conStr = ConfigurationManager.ConnectionStrings["MyDataBase"].ConnectionString;
                using (SqlConnection dbcon = new SqlConnection(conStr))
                {
                    dbcon.Open();
                    using (SqlCommand dbcmd = dbcon.CreateCommand())
                    {
                        dbcmd.CommandText = "SELECT Steps.StepNumber, Steps.Idx_StepId "
                            + "FROM ProdStepJoin "
                            + "INNER JOIN Steps ON Steps.Idx_StepId = ProdStepJoin.Idx_StepId "
                            + "INNER JOIN Products ON Products.Idx_ProductId = ProdStepJoin.Idx_ProductId "
                            + "WHERE ProdStepJoin.Idx_ProductId = @id";
                        dbcmd.Parameters.Add("@id", SqlDbType.BigInt).Value = id;

                        DataTable prdStpJoinTbl = new DataTable();
                        SqlDataAdapter dbadapt = new SqlDataAdapter(dbcmd);
                        dbadapt.Fill(prdStpJoinTbl);

                        return prdStpJoinTbl;
                    }
                }
            }
            catch (Exception e)
            {
                DataTable prdStpJoinTbl = new DataTable();
                prdStpJoinTbl.Columns.Add("Exception", typeof(string));
                DataRow prdStpJoinRow = prdStpJoinTbl.NewRow();
                prdStpJoinRow[0] = e.Message;
                prdStpJoinTbl.Rows.Add(prdStpJoinRow);

                return prdStpJoinTbl;
            }
        }
    }
}

Example webpage with ProductId of 12 http://mywebsite.com/ViewProduct.aspx?id=12 ViewProduct.aspx:

<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
    <hgroup class="title">
        <h1><%: Title %></h1>
    </hgroup>

    <asp:GridView ID="tbl_ProdStepJoin" runat="server" >
    </asp:GridView>

</asp:Content>

ViewProduct.aspx CodeBehind:

protected void Page_Load(object sender, EventArgs e)
{
    string productId = Request.QueryString["id"];
    ProductOps viewPrdOps = new ProductOps();

    using (DataTable prdStpJoinTbl = viewPrdOps.ProdStepJoin(productId))
    {
        if (prdStpJoinTbl != null)
        {
            tbl_ProdStepJoin.DataSource = prdStpJoinTbl;
        }
        else
        {
            tbl_ProdStepJoin.DataSource = null;
            Response.Write("Datasource is null");
        }

        tbl_ProdStepJoin.DataBind();
    }
}

My problem is how can I view each step one by one and stop at the last step?

Current Result:

StepNumber  Idx_StepId
1           127
2           128
3           129
4           130
5           131
6           132
7           133
8           134
9           135
10          136
11          137
12          138
13          139
14          140

Expected Result:

StepNumber  Idx_StepId
    1          127
         Next [Button or Link]
   **New Page or GridView**
StepNumber  Idx_Stepid
    2          128
         Next [Button or Link]
    Etc until step 14

Related posts

Recent Viewed