博客园 联系 订阅 订阅 管理  

Blog Stats

News

随笔分类

文章分类

随笔档案

相册

.NET设计模设、高级编程

项目管理论坛

nc's world:

天行健,君子以自强不息
地势坤,君子以厚德载物

2006年12月21日 #

 

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
posted @ 2006-12-21 08:33 nicesnow 阅读(56) 评论(0) 编辑