在没有数据库的情况下从gridview添加/删除行 [英] Add/Delete rows from gridview without database
本文介绍了在没有数据库的情况下从gridview添加/删除行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在不使用数据库的情况下将行添加到gridview,如下面的代码
如何从gridview删除行
hi ,
am adding rows to the gridview without using a database like below code
how can i delete the row from gridview
public static DataTable dt;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
dt = new DataTable();
DataRow dr = null;
dt.Columns.Add(new DataColumn("RowNumber", typeof(string)));
dt.Columns.Add(new DataColumn("Column1", typeof(string)));
dt.Columns.Add(new DataColumn("Column2", typeof(string)));
dr = dt.NewRow();
dr["RowNumber"] = 1;
dr["Column1"] = "column1cell";
dr["Column2"] = "column2cell";
dt.Rows.Add(dr);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (dt.Rows.Count > 0)
{
dt.Rows.RemoveAt(0);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
推荐答案
^ ]
点击此链接,看看如何在datagridview中设置编辑,删除.....:)
http://www.codersource.net/asp-net/asp-net-2-0/grid-view-control-in-asp-net-2-0.aspx[^]
Follow this link and see how to set the EDITING, DELETING in datagridview........:)
hi,
我已使网格视图的选定行可见= false
此
用过的会话
hi ,
i have made the selected row of the grid view visible=false
used session for this
DataTable table = (DataTable)Session["CurrentData"];
for (int i = GridView1.Rows.Count - 1; i >= 0; i--)
{
CheckBox chkbox = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("selector");
if (chkbox.Checked)
{
GridView1.Rows[i].Visible = false;
}
}
这里的选择器是gridview复选框ID
here the selector is the gridview checkbox id
DataTable table = (DataTable)Session["CurrentData"];
for (int i = GridView1.Rows.Count - 1; i >= 0; i--)
{
CheckBox chkbox = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("selector");
if (chkbox.Checked)
{
// GridView1.Rows[i].Visible = false;
myDt.Rows.RemoveAt(i);
DataTable myDt1 = (DataTable)Session["tabel"];
GridView1.DataSource = myDt1;
GridView1.DataBind();
}
}
这篇关于在没有数据库的情况下从gridview添加/删除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文