博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
用TableAdapter创建DataTable定义及查询
阅读量:4652 次
发布时间:2019-06-09

本文共 2157 字,大约阅读时间需要 7 分钟。

Default.aspx

View Code
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>    用TableAdapter创建DataTable定义及查询    

Default.aspx.cs

View Code
using System;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;using System.Data.SqlClient;public partial class _Default : System.Web.UI.Page {    dsInfoTableAdapters.tb_infTableAdapter adapter;    protected void Page_Load(object sender, EventArgs e)    {        if (adapter == null)        {            adapter = new dsInfoTableAdapters.tb_infTableAdapter();//实例化TableAdapter        }        if (!IsPostBack)        {            showEmployees();//显示GridView控件中数据        }    }    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)    {        gvInfo.PageIndex = e.NewPageIndex;        gvInfo.DataBind();        showEmployees();    }    //用GridView显示数据    protected void showEmployees()    {        gvInfo.DataSource = adapter.GetData();//调用TableAdapter类中的GetData()执行查询数据操作        gvInfo.DataBind();//绑定GridView控件    }    protected void gvInfo_RowDataBound(object sender, GridViewRowEventArgs e)    {        if (e.Row.RowType == DataControlRowType.DataRow)        {            string gIntro = e.Row.Cells[3].Text;            e.Row.Cells[3].Text = StrHelper.GetFirstString(gIntro, 12);//指定显示的内容并限定其长度        }    }}

 

转载于:https://www.cnblogs.com/hsw-2013/archive/2013/03/16/2962439.html

你可能感兴趣的文章
js 逻辑与 逻辑或
查看>>
带有key参数的函数filter,map,max,min
查看>>
python之函数
查看>>
网上资源工具
查看>>
POJ 3264 RMQ水题
查看>>
[Editor(typeof(ImageUrlEditor), typeof(UITypeEditor))]无效的可能原因
查看>>
Spring AOP
查看>>
C++输出数组名
查看>>
hdu 1018 Big Number
查看>>
普通表转换成分区表
查看>>
hdu1290
查看>>
解数独小游戏的暴力算法以及c语言代码
查看>>
Windows下的Memcache安装与测试教程
查看>>
MapGuide源码编译(图文详解)
查看>>
[连载型] Neutron系列(20):Neutron L3 Agent HA 之 虚拟路由冗余协议(VRRP)【下】...
查看>>
各种类型大小
查看>>
浅谈c语言程序为什么需要内存 栈又是什么?
查看>>
阿里云linux的nginx下面配置多站点
查看>>
Python函数: any()和all()的用法
查看>>
(顶级域名)一级域名和二级域名的区别
查看>>