Click here to Skip to main content
15,907,497 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How do I display records one by one on a button click in ASP .NET
Posted
Comments
KaushalJB 5-May-15 6:59am    
Write some code and display data in GridView !!!!

1 solution

You use formview for this a sample code:


Just change SqlDataSource control according to ur requirement

XML
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    </div>
    <asp:FormView ID="FormView1" runat="server" DataKeyNames="CLIENT_NO"
        DataSourceID="SqlDataSource1">
        <EditItemTemplate>
            CLIENT_NO:
            <asp:Label ID="CLIENT_NOLabel1" runat="server"
                Text='<%# Eval("CLIENT_NO") %>' />
            <br />
            PARTY_NM_ADDRS:
            <asp:TextBox ID="PARTY_NM_ADDRSTextBox" runat="server"
                Text='<%# Bind("PARTY_NM_ADDRS") %>' />
            <br />
            TOT_RCVD:
            <asp:TextBox ID="TOT_RCVDTextBox" runat="server"
                Text='<%# Bind("TOT_RCVD") %>' />
            <br />
            TOT_DUE:
            <asp:TextBox ID="TOT_DUETextBox" runat="server" Text='<%# Bind("TOT_DUE") %>' />
            <br />
            <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
                CommandName="Update" Text="Update" />
            &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server"
                CausesValidation="False" CommandName="Cancel" Text="Cancel" />
        </EditItemTemplate>
        <InsertItemTemplate>
            PARTY_NM_ADDRS:
            <asp:TextBox ID="PARTY_NM_ADDRSTextBox" runat="server"
                Text='<%# Bind("PARTY_NM_ADDRS") %>' />
            <br />
            TOT_RCVD:
            <asp:TextBox ID="TOT_RCVDTextBox" runat="server"
                Text='<%# Bind("TOT_RCVD") %>' />
            <br />
            TOT_DUE:
            <asp:TextBox ID="TOT_DUETextBox" runat="server" Text='<%# Bind("TOT_DUE") %>' />
            <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>
            CLIENT_NO:
            <asp:Label ID="CLIENT_NOLabel" runat="server" Text='<%# Eval("CLIENT_NO") %>' />
            <br />
            PARTY_NM_ADDRS:
            <asp:Label ID="PARTY_NM_ADDRSLabel" runat="server"
                Text='<%# Bind("PARTY_NM_ADDRS") %>' />
            <br />
            TOT_RCVD:
            <asp:Label ID="TOT_RCVDLabel" runat="server" Text='<%# Bind("TOT_RCVD") %>' />
            <br />
            TOT_DUE:
            <asp:Label ID="TOT_DUELabel" runat="server" Text='<%# Bind("TOT_DUE") %>' />
            <br />
        </ItemTemplate>
    </asp:FormView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:SKTConnectionString %>"
        SelectCommand="SELECT * FROM [CLIENT_DET_SMRY]"></asp:SqlDataSource>
    <asp:Button ID="Button1" runat="server" Text="Next" onclick="Button1_Click" />

    </form>
</body>
</html>



Code behind A button for next record

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        FormView1.PageIndex = FormView1.PageIndex + 1;
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900