惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
CXSECURITY Database RSS Feed - CXSecurity.com
Stack Overflow Blog
Stack Overflow Blog
月光博客
月光博客
T
Threat Research - Cisco Blogs
小众软件
小众软件
有赞技术团队
有赞技术团队
酷 壳 – CoolShell
酷 壳 – CoolShell
Apple Machine Learning Research
Apple Machine Learning Research
C
Cyber Attacks, Cyber Crime and Cyber Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Tailwind CSS Blog
Cisco Talos Blog
Cisco Talos Blog
V
V2EX
博客园 - 【当耐特】
C
Cybersecurity and Infrastructure Security Agency CISA
Hugging Face - Blog
Hugging Face - Blog
The Cloudflare Blog
The Last Watchdog
The Last Watchdog
Simon Willison's Weblog
Simon Willison's Weblog
T
Threatpost
S
Secure Thoughts
O
OpenAI News
P
Proofpoint News Feed
S
SegmentFault 最新的问题
Forbes - Security
Forbes - Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Application and Cybersecurity Blog
Application and Cybersecurity Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Last Week in AI
Last Week in AI
宝玉的分享
宝玉的分享
Scott Helme
Scott Helme
T
Tenable Blog
A
Arctic Wolf
L
LINUX DO - 热门话题
爱范儿
爱范儿
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
www.infosecurity-magazine.com
www.infosecurity-magazine.com
V
Visual Studio Blog
Hacker News: Ask HN
Hacker News: Ask HN
Hacker News - Newest:
Hacker News - Newest: "LLM"
腾讯CDC
博客园 - Franky
WordPress大学
WordPress大学
Know Your Adversary
Know Your Adversary
博客园_首页
雷峰网
雷峰网
IT之家
IT之家
PCI Perspectives
PCI Perspectives
L
LINUX DO - 最新话题
H
Heimdal Security Blog

博客园 - Airship

lrc 文件格式 不打算在cnblogs灌水文了,转移阵地到 http://airship.blogdriver.com 爱情保鲜——永和豆浆——MSDN翻译——1点18分 丁香花——有小成 I'm not the only one starin' at the sun 芦沟桥——抗日纪念馆 1个小时1000字 左手感觉怪怪的 停止翻译工作喽 头儿说要改版stuthu界面模版 B7和弦——丁香花——修炼中 GNU is a hack Done with The First MSDN essay 翻译的头晕脑胀,喘口气先 哈 做了个职业倾向测试 今天跟我们动振所所长聊了会儿 MSDN翻译工作启动 车公庄-源泽兴-天津一中 航天离我而远去 I know you will read this
DataGrid的翻页和动态显示
Airship · 2005-10-06 · via 博客园 - Airship

不能总是写水文了。今天编datagrid,顺便贴点常用代码。下面是一段通用的设置分页的代码。myd是我们的datagrid实例。

分页代码:

        private void Grid_Change(object sender,System.Web.UI.WebControls.DataGridPageChangedEventArgs e) 
        {
            myd.CurrentPageIndex 
= e.NewPageIndex;
            Get_Data(); 
        }

动态显示代码:

private void OnItemDataBound(object sender,    System.Web.UI.WebControls.DataGridItemEventArgs e)
        {
            
if (e.Item.ItemType!=ListItemType.Header && e.Item.ItemType!=ListItemType.Footer) 
            {
                
object di = e.Item.DataItem;
                
int isRead = Convert.ToInt16(DataBinder.Eval(di, "Is_Read"));
                
if (isRead == 0 )
                {
                    e.Item.Cells[
5].Text = "尚未回复";
                    
//e.Item.ForeColor = System.Drawing.Color.Red;  
                } 
                
else if ( isRead ==1)
                {
                    e.Item.Cells[
5].Text = "已经回复";
                }
            }

        }

然后要这样设置

private void InitializeComponent()
        {
            
this.myd.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.Grid_Change);
            
this.myd.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.OnItemDataBound);
            
this.Load += new System.EventHandler(this.Page_Load);

        }

总结一下:这段代码是用在User Control里的。在Web Control里,我们用CreateChildControl的方法Create一个DataGrid,而这种利用DataGrid自带的分页机制是不能用在Web Control里的,引用Web Control时必然需要一个aspx页,这个aspx页的Page_Load机制,及Post_Back等机制,导致触发事件后,无法保存上一个状态。在Web Control里利用自带分页功能的方法还有待研究。