client side event??<table id=tbl>
</table><input type=button value=add onclick="addRow()"><script language="javascript">
function addRow()
{
  var row = tbl.insertRow();
  row.onclick = function () { alert(this.rowIndex + "n" + this.innerHTML);}  var cell = row.insertCell();
  cell.innerText = new Date();
  cell = row.insertCell();
  cell.innerText = new Date();
}
</script>

解决方案 »

  1.   

    <body MS_POSITIONING="FlowLayout">
    <form id="Form1" method="post" runat="server">
    <asp:Table id="Table1" runat="server"></asp:Table>
    </form>
    </body>
    protected System.Web.UI.WebControls.Table Table1;

    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    System.Web.UI.WebControls.TableRow DR = new System.Web.UI.WebControls.TableRow();
    System.Web.UI.WebControls.TableCell TC = new System.Web.UI.WebControls.TableCell();
    TC.Text = "aaaa";
    DR.Controls.Add(TC);
    DR.Attributes["onclick"]="JavaScript:alert(\"您单击了第一行\");";
    Table1.Rows.Add(DR);
    }
      

  2.   

    : houjianxun(三千弱水,独取一瓢清泉) 
    我用的是HTML控件table,不是服务器端控件。我要用Javascript动态的加入一行。
    思归的方法应该是可以的,可是我调试老是不成功。
      

  3.   

    what browser are you using? I tested my code on IE6 SP1, it works fine
      

  4.   

    呵呵,原来是我在function后少加了一个()。
    谢谢思归。
    这个问题可能对大家有时会有点帮助。
    让大家看看我就结贴!
      

  5.   

    哦,client saucer的方法是对的你的浏览器不支持脚本?
      

  6.   

    思归大哥的程序没用任何Server Control,全都是静态的HTML代码,你说你用了Table Html Server Control,不知道有没有影响
      

  7.   

    为row加上onclick事件处理方法也是可以的<script>
    var i = 0;
    var nowRow = null;
    function trSelect()
    {

    if(nowRow != null)
      nowRow.style.background="#dff3fb";
    this.style.background = "#A5baf7";
    nowRow = this;
    }
    function trDblClick()
    {
    if(nowRow != null)
      alert("双击了");
    }
    function addRow()
    {

    i = i + 1;
    var newRow = document.all("Table1").insertRow();
    newRow.style.height = "25";
    newRow.style.backgroundColor = "#DFF3FB";
    newRow.onclick = trSelect;
    newRow.ondblclick = trDblClick;
    newRow.align ="center";
    newRow.style.cursor = "hand";
    //构造页面表格的界面显示
    var newCell = newRow.insertCell();
    newCell.innerHTML = "Hello";
    newCell = newRow.insertCell();
    newCell.innerHTML = "world"; 
    }
    </script>
    <body>
    <form id=form1>
    <input type=button onclick="addRow()" id="btnAdd" value="添加行">
    <table id="Table1"  borderColor="#dff3fb" cellSpacing="0" cellPadding="0" width="100%" border="1">
    <tr bgcolor="green">
    <td>列1</td>
    <td>列2</td>
    </tr>
    </table>
    </form>
    </body>