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

推荐订阅源

Google DeepMind News
Google DeepMind News
博客园 - 司徒正美
WordPress大学
WordPress大学
爱范儿
爱范儿
小众软件
小众软件
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
罗磊的独立博客
博客园_首页
V
V2EX
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Tailwind CSS Blog
大猫的无限游戏
大猫的无限游戏
The Cloudflare Blog
MyScale Blog
MyScale Blog
IT之家
IT之家
H
Help Net Security
Blog — PlanetScale
Blog — PlanetScale
Microsoft Security Blog
Microsoft Security Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Recent Announcements
Recent Announcements
F
Fortinet All Blogs
The GitHub Blog
The GitHub Blog
Y
Y Combinator Blog
人人都是产品经理
人人都是产品经理

博客园 - nicesnow

.net 3.0 12个.net 开发者值得去读的国外Blog 如何在DNN站点的虚拟目录下安装CS 使用url与内部fileid绑定datalist中的图片 控制某个空间滚动效果的实现(scroll bar) update数据库表--存储过程 今天犯的一个错误,学得到不少东西,哈哈 Commerce starter kit数据库分析 DNN修改登录次数限制 Ajax程序设计入门 软件工程之需求分析(二) 软件工程之需求分析(一) 关于民工。。。感人! 国外C#开源系统一览表 关于SharpWebMail配置调试 怎样将表中数据导出,形成insert into 表名 values(...)这样的语句? 怎样将表中数据导出,形成insert into 表名 values(...)这样的语句? 怎样才是一个真正的DBA? 微软提供的关于其它数据库迁移到SQL Server的技术指南
datagrid 模版列操作问题
nicesnow · 2006-12-21 · via 博客园 - nicesnow

Thanks for posting in this group.
I think maybe you bind the database data into your datagrid every time 
in
WebForm load 
event.
Because when you click the button, the page postback to the server,
Page_Load 
event fires, the datagrid will be rebind again. So the
ItemCommand will not fire(the datagrid was reinitialized). (You can
demonstrate 
this through add a breakpoint in ItemCommand eventhandler)
So you should bind the datagrid only when the page 
is not postback.
Code snippet like 
this:

//I use default sqlserver database to fill the datagrid
private void Page_Load(object sender, System.EventArgs e)
{
    
// Put user code to initialize the page here
    
//Response.Write(Session[0]);
    Response.Write(this.GetPostBackEventReference(hoho));
    
if(!IsPostBack)
    
{
        SqlDataAdapter adapter
=new SqlDataAdapter("select * from
jobs","server=localhost;database=pubs;uid=sa;pwd=");
        DataSet ds=new DataSet();
        adapter.Fill(ds);
        DataGrid1.DataSource
=ds;
        DataGrid1.DataBind();
    }

}


this.DataGrid1.ItemCommand += new
System.Web.UI.WebControls.DataGridCommandEventHandler(
this.DataGrid1_ItemCom
mand);

private void DataGrid1_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
    
if(e.CommandName=="buttonclick")
    
{
        Response.Write(e.Item.Cells[
3].Text);
    }

}


Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure
! - www.microsoft.com/security
This posting 
is provided "as is" with no warranties and confers no rights