private void gv01_RowCommand(object sender,GridViewCommandEventArgs e)
  {
    int rowIndex=-1;
GridViewRow row=null;

if(e.CommandName=="Update")
{
   rowIndex = Convert.ToInt32(e.CommandArgument);
           row = gv01.Rows[rowIndex];
   LinkButton btn=(LinkButton)row.Cells[3].Controls[0];
   btn.Attributes.Add("onclick","return confirm('確定要更新此筆附件嗎?')");

           //怎样当e.CommandName=="Update"时加上客户端事件?上面的代码不行啊
}
  }谢谢

解决方案 »

  1.   


    Put your the code (in blue color) to RowDataBound event
      

  2.   

    在GridView的RowDataBound中注册客户端事件
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
         if(e.Row.RowType == DataControlRowType.DataRow)
        {
        //你的代码
        }
    }
      

  3.   

    但是我只要当Update时并且是要Updated之前不是在点击Edit时就出现,又怎样弄?
    谢谢
      

  4.   

    解決,我是寫在DataBound事件裡的不是在RowDataBound事件裡代碼:  private void gv01_DataBound(object sender,EventArgs e)
      {
    string script="if document.getElementById('').size<=0 {alert('請選擇附件!');return false;}";

    if(gv01.EditIndex>-1)
    {
      GridViewRow erow=gv01.Rows[gv01.EditIndex];
      
      LinkButton btn=(LinkButton)erow.Cells[3].Controls[0];
      btn.Attributes.Add("onclick",script);
      //btn.Attributes.Add("onclick","return confirm('確定要更新此筆附件嗎?')");
    }
      }
      

  5.   

    解決,我是寫在DataBound事件裡的不是在RowDataBound事件裡 代碼:   private void gv01_DataBound(object sender,EventArgs e) 
      { 
    string script="if document.getElementById('').size <=0 {alert('請選擇附件!');return false;}"; if(gv01.EditIndex>-1) 

      GridViewRow erow=gv01.Rows[gv01.EditIndex]; 
       
      LinkButton btn=(LinkButton)erow.Cells[3].Controls[0]; 
      btn.Attributes.Add("onclick",script); 
      //btn.Attributes.Add("onclick","return confirm('確定要更新此筆附件嗎?')"); 

      }---------------------------------------
    經測試,沒有用