因为要把按钮放在一行内容中,而不是单独成一列,所以不能使用模版。
请问有什么办法?

解决方案 »

  1.   

    可以
    在ItemCreated事件内 放
      

  2.   

    <%@ Page Language="C#" Debug="true" %>
    <%@ Import NameSpace="System.Data"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="gb2312">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <meta http-equiv="Content-Language" content="gb2312" />
    <meta content="all" name="robots" />
    <meta name="Author" content="[email protected] ,活靶子" />
    <meta name="Copyright" content="www.AspxBoy.Com,自由版权,任意转载." />
    <meta name="Description" content="www.AspxBoy.Com" />
    <meta name="Keywords" content="www.AspxBoy.Com,活靶子,huobazi" />
    <title> New New Document</title>
    <script language="c#" runat="server">protected void Item_Created(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
       if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
       {
    if( e.Item.ItemIndex == 1 )//第2行
    {
    TextBox box = new TextBox();
    box.ID="myTextBox";
    box.Text = e.Item.ItemIndex.ToString();
    e.Item.Cells[0].Controls.Add(box);
    }
       }
    }
    protected void Item_Command(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
    TextBox box = (TextBox)e.Item.FindControl("myTextBox");
    if(box != null)
    {
    Response.Write(box.Text);
    }
    }protected  void BindGrid()
    {
          dg.DataSource =  new string[]{"a","a","a","a","a","a"};
      dg.DataBind();
    }protected void Page_Load(Object sender, EventArgs e) 
    {
        if(!IsPostBack) 
        {
           BindGrid();
        }
    }</script>
    </head>
    <body>
    <form id="aa" runat="server"><asp:datagrid id="dg" runat="server" 
    OnItemCreated="Item_Created"
    OnItemCommand="Item_Command"
    AutoGenerateColumns="False">
    <Columns>
    <asp:ButtonColumn Text="我是按钮,按我一下" ButtonType="PushButton" CommandName="push"></asp:ButtonColumn>
    </Columns>
    </asp:datagrid></form>
    </body>
    </html>