Gridview分页增删改

本文概述了AI音视频处理领域的关键技术,包括视频分割、语义识别、自动驾驶、AR、SLAM等,并探讨了其在实际应用中的作用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//前台


<head runat="server">
    <title></title>
    <script type="text/javascript">
        function showinfo() {
            if (confirm('真的要删除吗') == false)
                return false;
    }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table>
            <tr>
                <td>
                    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
                        <Columns>
                            <asp:BoundField DataField="Id" HeaderText="编号" />
                            <asp:BoundField DataField="NewsTitle" HeaderText="标题" />
                            <asp:BoundField DataField="NewsContent" HeaderText="内容" />
                            <asp:BoundField DataField="RealName" HeaderText="创建者" />
                            <asp:BoundField DataField="CreateTime" DataFormatString="{0:yyyy-MM-dd hh:mm:ss}"
                                HeaderText="创建时间" />
                            <asp:BoundField DataField="ClassName" HeaderText="类别" />
                            <asp:TemplateField HeaderText="操作">
                                <ItemTemplate>
                                    <asp:LinkButton ID="btnEdit" runat="server" CommandArgument='<%#Eval("Id") %>' onclick="btnEdit_Click">编辑</asp:LinkButton>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="操作">
                                <ItemTemplate>
                                    <asp:LinkButton ID="btnDelete" CommandArgument='<%#Eval("Id") %>' 
                                        runat="server" onclick="btnDelete_Click"  OnClientClick="return showinfo();">删除</asp:LinkButton>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:LinkButton ID="btnFirst" runat="server" onclick="btnFirst_Click">第一页 </asp:LinkButton>
                    <asp:LinkButton ID="btnPre" runat="server" onclick="btnPre_Click">上一页</asp:LinkButton>
                    <asp:LinkButton ID="btnNext" runat="server" onclick="btnNext_Click">下一页</asp:LinkButton>
                    <asp:LinkButton ID="btnLast" runat="server" onclick="btnLast_Click">最后一页</asp:LinkButton>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>

//后台

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;


namespace WebApplication1
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        int pagesize = 20;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack==false)
            {
                ViewState["pageindex"] = 1;
                GetCount();
                LoadData();
            }
        }
        private void GetCount()
        {
string strcon = @"Data Source=PC-YZC\SQLEXPRESS;Initial Catalog=News;Persist Security Info=True;User ID=sa;Password=1992051";
            SqlConnection conn = new SqlConnection(strcon);
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            //每次都显式打开
            conn.Open();
            //cmd.CommandText = "SELECT T1.Id,T1.NewsTitle,SUBSTRING(T1.NewsContent,0,20)+'......' AS NewsContent,T1.CreateTime,T2.ClassName,T3.RealName FROM T_News1 T1 INNER JOIN T_NewsClass T2 ON T1.ClassId=T2.ClassId INNER JOIN T_User T3 ON T1.NewsCreator=T3.UserId";
            cmd.CommandText = " SELECT COUNT(*) FROM T_News1";
            int totalcount=Convert.ToInt32(cmd.ExecuteScalar());
            cmd.Dispose();
            conn.Dispose();


            if (totalcount % pagesize == 0)
            {
                ViewState["pagelastindex"] = totalcount / pagesize;
            }
            else
            {
                ViewState["pagelastindex"] = totalcount / pagesize + 1;
            }


        }
        private void LoadData()
        {
string strcon = @"Data Source=PC-YZC\SQLEXPRESS;Initial Catalog=News;Persist Security Info=True;User ID=sa;Password=1992051";
            SqlConnection conn = new SqlConnection(strcon);
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            //每次都显式打开
            conn.Open();
            //cmd.CommandText = "SELECT T1.Id,T1.NewsTitle,SUBSTRING(T1.NewsContent,0,20)+'......' AS NewsContent,T1.CreateTime,T2.ClassName,T3.RealName FROM T_News1 T1 INNER JOIN T_NewsClass T2 ON T1.ClassId=T2.ClassId INNER JOIN T_User T3 ON T1.NewsCreator=T3.UserId";
            cmd.CommandText = "SELECT * FROM (SELECT ROW_NUMBER() OVER(ORDER BY T1.Id)AS rownumber, T1.Id,T1.NewsTitle,SUBSTRING(T1.NewsContent,0,20)+'......' AS NewsContent,T1.CreateTime,T2.ClassName,T3.RealName  FROM T_News1 T1 INNER JOIN T_NewsClass T2 ON T1.ClassId=T2.ClassId INNER JOIN T_User T3 ON T1.NewsCreator=T3.UserId)A WHERE A.rownumber>(@pageindex-1)*@pagesize AND A.rownumber<=@pageindex*@pagesize";
            cmd.Parameters.AddWithValue("@pageindex",ViewState["pageindex"]);
            cmd.Parameters.AddWithValue("@pagesize", pagesize);
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            adapter.Fill(dt);
            cmd.Dispose();
            conn.Dispose();
            //将查询出来的数据绑定到GridView
            //原来需要手动拼接字符串的工作由GridView代劳了
            this.GridView1.DataSource = dt;
            //DataBind负责拼接字符串
            this.GridView1.DataBind();
        }


        protected void btnFirst_Click(object sender, EventArgs e)
        {
            ViewState["pageindex"] = 1;
            LoadData();
        }


        protected void btnPre_Click(object sender, EventArgs e)
        {
            int pageindex = Convert.ToInt32(ViewState["pageindex"]);
            if (pageindex > 1)
            {
                pageindex--;
                ViewState["pageindex"] = pageindex;
                LoadData();
            }
        }


        protected void btnNext_Click(object sender, EventArgs e)
        {
            int pageindex = Convert.ToInt32(ViewState["pageindex"]);
            if (pageindex<Convert.ToInt32(ViewState["pagelastindex"]))
            {
                pageindex++;
                ViewState["pageindex"] = pageindex;
                LoadData();
            }
        }


        protected void btnLast_Click(object sender, EventArgs e)
        {
            ViewState["pageindex"] = ViewState["pagelastindex"];
            LoadData();
        }


        protected void btnEdit_Click(object sender, EventArgs e)
        {
            
            LinkButton btnEdit = sender as LinkButton;


            Response.Redirect("WebEdit2.aspx?id=" + btnEdit.CommandArgument);
        }


        protected void btnDelete_Click(object sender, EventArgs e)
        {
            LinkButton btnDelete = sender as LinkButton;
string strcon = @"Data Source=PC-YZC\SQLEXPRESS;Initial Catalog=News;Persist Security Info=True;User ID=sa;Password=1992051";
            SqlConnection conn = new SqlConnection(strcon);
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;           
            conn.Open();          
            cmd.CommandText = "DELETE FROM T_News1 WHERE Id=@id";
            cmd.Parameters.AddWithValue("@id",btnDelete.CommandArgument);
            if (cmd.ExecuteNonQuery() > 0)
            {
                LoadData();
            }
            cmd.Dispose();
            conn.Dispose();
        }
    }
}

///////////////////////////////////////


////////////////////////////前台

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebEdit2.aspx.cs" Inherits="WebApplication1.WebEdit2" %>


<!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>
        <table>
            <tr>
                <td>
                    编号
                </td>
                <td>
                    <asp:TextBox ID="txtId" runat="server" Enabled="False" ReadOnly="True" 
                        Width="254px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    标题
                </td>
                <td>
                    <asp:TextBox ID="txtTitle" runat="server" Width="250px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    内容
                </td>
                <td>
                    <asp:TextBox ID="txtContent" runat="server" Height="223px" TextMode="MultiLine" 
                        Width="259px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    类别
                </td>
                <td>
                    <asp:DropDownList ID="ddlClassName" runat="server">
                    </asp:DropDownList>
                  
                </td>
            </tr>
            <tr>
                <td>
                    用户
                </td>
                <td>
                    <asp:DropDownList ID="ddlUser" runat="server">
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
               
                <td align="center" colspan="2">
                    <asp:Button ID="btnUpdate" runat="server" Text="保存" onclick="btnUpdate_Click" />
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>

////////////////////////////////后台

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;


namespace WebApplication1
{
    public partial class WebEdit2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string id = Request.QueryString["id"];
                GetNews1(id);

                
             
            }
        }
        //绑定用户
        private void LoadUser()
        {
string strcon = @"Data Source=PC-YZC\SQLEXPRESS;Initial Catalog=News;Persist Security Info=True;User ID=sa;Password=1992051";
            SqlConnection conn = new SqlConnection(strcon);
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            conn.Open();
cmd.CommandText = "SELECT * FROM T_User";
           
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            adapter.Fill(dt);
            cmd.Dispose();
            conn.Dispose();
            this.ddlUser.DataSource = dt;
            this.ddlUser.DataTextField = "RealName";
            this.ddlUser.DataValueField = "UserId";
            this.ddlUser.DataBind();
        }
        //绑定类别
        private void LoadClass()
        {
string strcon = @"Data Source=PC-YZC\SQLEXPRESS;Initial Catalog=News;Persist Security Info=True;User ID=sa;Password=1992051";
            SqlConnection conn = new SqlConnection(strcon);
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            conn.Open();
            cmd.CommandText = "SELECT * FROM T_NewsClass";


            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            adapter.Fill(dt);
            cmd.Dispose();
            conn.Dispose();
            this.ddlClassName.DataSource = dt;
            this.ddlClassName.DataTextField = "ClassName";
            this.ddlClassName.DataValueField = "ClassId";
            this.ddlClassName.DataBind();
        }


        private void GetNews1(string id)
        {
string strcon = @"Data Source=PC-YZC\SQLEXPRESS;Initial Catalog=News;Persist Security Info=True;User ID=sa;Password=1992051";
            SqlConnection conn = new SqlConnection(strcon);
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;            
            conn.Open();           
            cmd.CommandText = "SELECT * FROM T_News1 WHERE Id=@id";            
            cmd.Parameters.AddWithValue("@id",id);
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            adapter.Fill(dt);
            cmd.Dispose();
            conn.Dispose();


            txtId.Text = dt.Rows[0]["Id"].ToString();
            txtTitle.Text = dt.Rows[0]["NewsTitle"].ToString();
            txtContent.Text = dt.Rows[0]["NewsContent"].ToString();
//绑定默认用户
            LoadUser();
            string userid= dt.Rows[0]["NewsCreator"].ToString();
            foreach (ListItem item in this.ddlUser.Items)
            {
                if (item.Value == userid)
                {
                    item.Selected = true;
                }
            }
//绑定默认类别
            LoadClass();
            string classid = dt.Rows[0]["ClassId"].ToString();
            foreach (ListItem item in this.ddlClassName.Items)
            {
                if (item.Value == classid)
                {
                    item.Selected = true;
                }
            }
        }


        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            #region 获取用户输入和选择的值
            string title = txtTitle.Text;
            string content = txtContent.Text;
            string userid = this.ddlUser.SelectedItem.Value;
            string classid = this.ddlClassName.SelectedItem.Value;
            #endregion


            #region 更改数据
string strcon = @"Data Source=PC-YZC\SQLEXPRESS;Initial Catalog=News;Persist Security Info=True;User ID=sa;Password=1992051";
            SqlConnection conn = new SqlConnection(strcon);
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;            
            conn.Open();
           
            cmd.CommandText = "UPDATE T_News1 SET NewsTitle=@newstitle,NewsContent=@newscontent,NewsCreator=@newscreator,ClassId=@classid WHERE Id=@id";
            cmd.Parameters.AddWithValue("@newstitle",title);
            cmd.Parameters.AddWithValue("@newscontent", content);
            cmd.Parameters.AddWithValue("@newscreator", userid);
            cmd.Parameters.AddWithValue("@classid", classid);
            cmd.Parameters.AddWithValue("@id", txtId.Text);


            if (cmd.ExecuteNonQuery() > 0)
            {
                Response.Redirect("WebForm1.aspx");
            }
            #endregion
        }
    }
}

内容概要:本文详细探讨了基于MATLAB/SIMULINK的多载波无线通信系统仿真及性能分析,重点研究了以OFDM为代表的多载波技术。文章首先介绍了OFDM的基本原理和系统组成,随后通过仿真平台分析了不同调制方式的抗干扰性能、信道估计算法对系统性能的影响以及同步技术的实现与分析。文中提供了详细的MATLAB代码实现,涵盖OFDM系统的基本仿真、信道估计算法比较、同步算法实现和不同调制方式的性能比较。此外,还讨论了信道特征、OFDM关键技术、信道估计、同步技术和系统级仿真架构,并提出了未来的改进方向,如深度学习增强、混合波形设计和硬件加速方案。; 适合人群:具备无线通信基础知识,尤其是对OFDM技术有一定了解的研究人员和技术人员;从事无线通信系统设计与开发的工程师;高校通信工程专业的高年级本科生和研究生。; 使用场景及目标:①理解OFDM系统的工作原理及其在多径信道环境下的性能表现;②掌握MATLAB/SIMULINK在无线通信系统仿真中的应用;③评估不同调制方式、信道估计算法和同步算法的优劣;④为实际OFDM系统的设计和优化提供理论依据和技术支持。; 其他说明:本文不仅提供了详细的理论分析,还附带了大量的MATLAB代码示例,便于读者动手实践。建议读者在学习过程中结合代码进行调试和实验,以加深对OFDM技术的理解。此外,文中还涉及了一些最新的研究方向和技术趋势,如AI增强和毫米波通信,为读者提供了更广阔的视野。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值