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

推荐订阅源

有赞技术团队
有赞技术团队
M
MIT News - Artificial intelligence
Hugging Face - Blog
Hugging Face - Blog
博客园 - 聂微东
量子位
S
SegmentFault 最新的问题
V
Visual Studio Blog
博客园 - 【当耐特】
Apple Machine Learning Research
Apple Machine Learning Research
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
小众软件
小众软件
Stack Overflow Blog
Stack Overflow Blog
Vercel News
Vercel News
D
Docker
J
Java Code Geeks
博客园 - 三生石上(FineUI控件)
博客园 - Franky
Recent Announcements
Recent Announcements
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
MongoDB | Blog
MongoDB | Blog
D
DataBreaches.Net
Y
Y Combinator Blog
云风的 BLOG
云风的 BLOG
V
V2EX

博客园 - 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