如何在ASP .NET中单击按钮时逐个显示记录 [英] How do I display records one by one on a button click in ASP .NET

查看:83
本文介绍了如何在ASP .NET中单击按钮时逐个显示记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在ASP .NET中单击按钮逐个显示记录

How do I display records one by one on a button click in ASP .NET

推荐答案

您可以使用formview获取此示例代码:





只需根据你的要求更改SqlDataSource控件



You use formview for this a sample code:


Just change SqlDataSource control according to ur requirement

<%@ 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:按钮 ID = Button1 runat = server Text=\"Next\" onclick=\" Button1_Click\" />

</form>
</body>
</html>
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






Code behind A button for next record

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;
    }
}


这篇关于如何在ASP .NET中单击按钮时逐个显示记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆