当点击表格的某行时,将该行ID赋值给Text.value。_Page_Load里添加代码使得刷新页面时该行被删除
大神们帮帮我,是在是找不出错误来了。
就是没有办法实现删除行的功能。后天获取Text1.Value是什么都没有,为什么会这样呢_
前台代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default10.aspx.cs" Inherits="Default10" %>
<!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">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<p>
<input id="Text1" runat="server" type="text" onclick="return Text1_onclick()" /></p>
<table id="table1" runat="server" width="100%" border="1">
<tr id="row1" runat="server" onclick="Text1.value=(this.id)">
<td>第一行</td>
</tr>
<tr id="row2" runat="server" onclick="Text1.value=(this.id)">
<td>第二行</td>
</tr>
</table>
</form>
</body>
</html>
.CS的代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public partial class Default10 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(Text1.Value +"aaaaaaaa");
var p = (HtmlTableRow)this.FindControl(Text1.Value);
if(Text1.Value != null)
{
table1.Rows.Remove(p);
}
}
}