Dear All:
   我在DataGrid中加了一列Button,让用户进行删除确认。所以在后台写了如下代码:
Button DelButton = (Button)e.Item.Cells[2].Controls[0];
DelButton.Attributes.Add("onclick", "return confirm('Are you sure to delete this line?');");   程序可以正常运行,但我们并不能捕获客户是选择的Yes还是NO,所以我的问题是:怎样把DelButton.Attributes.Add("onclick", "return confirm('Are you sure to delete this line?');"); 这段代码写在客户端的HTML里面,而不是写在后台代码中?当用户确认时才提交,否则不提交。Aspx代码如下:
<asp:DataGrid id="CustGrid"......>
  <Columns>
  ........
    <asp:ButtonColumn HeaderText="编辑" Text="编辑" ButtonType="PushButton"         
HeaderStyle-HorizontalAlign="center"
ItemStyle-HorizontalAlign="center" CommandName="custdelete"/>
  </Columns>
</asp:DataGrid>谢谢各位!
Kent

解决方案 »

  1.   

    这样做没错呀
    你选了no它是不会递交的,选了yes才会运行server端呀
      

  2.   

    To: spland(spland)
      还有问题,可能我的后台代码放的位置不对,麻烦你帮我看看。
      我在DataGrid中加了一列Button,让用户进行删除确认。所以在后台写了如下代码:
       public void CustGrid_Del (Object sender, DataGridCommandEventArgs e){
           .........
           Button DelButton = (Button)e.Item.Cells[2].Controls[0];
           DelButton.Attributes.Add("onclick", "return confirm('Are you sure to delete this line?');");
           .......
       }   程序可以正常运行,但我们并不能捕获客户是选择的Yes还是NO,所以我的问题是:怎样把DelButton.Attributes.Add("onclick", "return confirm('Are you sure to delete this line?');"); 这段代码写在客户端的HTML里面,而不是写在后台代码中?当用户确认时才提交,否则不提交。Aspx代码如下:
    <asp:DataGrid id="CustGrid"
      .......
      OnItemCommand="CustGrid_Del" >
      <Columns>
      ........
        <asp:ButtonColumn HeaderText="编辑" Text="编辑" ButtonType="PushButton"         
    HeaderStyle-HorizontalAlign="center"
    ItemStyle-HorizontalAlign="center" CommandName="custdelete"/>
      </Columns>
    </asp:DataGrid>谢谢各位!
      

  3.   

    同意spland(spland) ,只有选择yes才会运行,否则什么也不会做!
      

  4.   

    Button DelButton = (Button)e.Item.Cells[2].Controls[0];
           DelButton.Attributes.Add("onclick", "return confirm('Are you sure to delete this line?');");这段代码应该写在item_create事件中吧
      

  5.   

    后台错了
    在ItemDataBound事件中绑定js