using System; using System.Collections.Generic; using System.Web.UI; namespace Web { public partial class a : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { Bind(); } } private void Bind() { List<String> ls = new List<String>(); for (int i = 0; i < 20; i++) { ls.Add("记录" + i.ToString()); } GridView1.DataSource = ls; GridView1.DataBind(); } } }
这个对你有帮助的应该
http://blog.csdn.net/downmoon/archive/2008/12/04/3444429.aspx
http://www.cnblogs.com/downmoon/archive/2007/12/30/1021151.html
http://blog.csdn.net/downmoon/archive/2007/12/14/1935654.aspx
{
removeptsb(e.RowIndex);
}void removeptsb(int rowindex) //删除--处理griview的RowDelete事件
{
if (ViewState["ptsb"] != null)
{
SBList[] newArray = (SBList[])ViewState["ptsb"];
ptsblist = new List<SBList>(newArray);
}
ptsblist.RemoveAt(rowindex);
RElist();
ViewState.Add("ptsb", ptsblist.ToArray());
GridViewptsb.DataSource = ptsblist;
GridViewptsb.DataBind();
}
可以用 js 来删除页面上的这一行。 但是,如果数据源里边的数据没有更新,gridview 重新绑定后又会出现的。
<head runat="server">
<title>无标题页</title>
<script language="javascript" >
function DelThisRow(obj)
{
var o = obj;
while( o.tagName!="TR")
{
o=o.parentNode;
}
o.parentNode.removeChild(o);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<a href="#" onclick="DelThisRow(this);return false;">删除</a>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
using System.Collections.Generic;
using System.Web.UI;
namespace Web
{
public partial class a : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Bind();
}
}
private void Bind()
{
List<String> ls = new List<String>();
for (int i = 0; i < 20; i++)
{
ls.Add("记录" + i.ToString());
}
GridView1.DataSource = ls;
GridView1.DataBind();
}
}
}