我是代码编写出的Table 显示到GridView上 调用控件自身的编辑删除功能
我不是直接调用数据库 所以实现编辑删除功能的代码要大家帮忙
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = GridView1.Rows[e.RowIndex];
string empno = row.Cells[0].Text;
string cname = ((TextBox)(row.Cells[1].Controls[0])).Text;
string dept = ((TextBox)(row.Cells[2].Controls[0])).Text;
string ext = ((TextBox)(row.Cells[3].Controls[0])).Text; string table = "Test_Report";
string[] field = new string[] { "CNAME", "DEPT", "EXT" };
string[] fieldValue = new string[] { cname, dept, ext };
string[] whereFiled = new string[] { "EMPNO" };
string[] whereValue = new string[] { empno };
}还有RowDeleting的代码 大家帮忙 谢谢
我不是直接调用数据库 所以实现编辑删除功能的代码要大家帮忙
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = GridView1.Rows[e.RowIndex];
string empno = row.Cells[0].Text;
string cname = ((TextBox)(row.Cells[1].Controls[0])).Text;
string dept = ((TextBox)(row.Cells[2].Controls[0])).Text;
string ext = ((TextBox)(row.Cells[3].Controls[0])).Text; string table = "Test_Report";
string[] field = new string[] { "CNAME", "DEPT", "EXT" };
string[] fieldValue = new string[] { cname, dept, ext };
string[] whereFiled = new string[] { "EMPNO" };
string[] whereValue = new string[] { empno };
}还有RowDeleting的代码 大家帮忙 谢谢
{
gv.EditIndex = e.RowIndex;
int id = int.Parse(gv.DataKeys[e.RowIndex].Value.ToString());
gv.EditIndex = -1;
BindData();
}protected void gv_RowEditing(object sender, GridViewEditEventArgs e)
{
this.gv.EditIndex = e.NewEditIndex;
BindData();
}
操作XML等文件
protected void grid1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
grid1.EditIndex = e.RowIndex;
int ID = Convert.ToInt32(grid1.DataKeys[e.RowIndex].Value.ToString()); //在这里,利用你已经取得的新数据,根据ID更新数据库 grid1.EditIndex = -1;
//重新绑定控件
}
private DataTable GetTable()
{
//获取数据源
DataTable dt = new DataTable("cart"); DataColumn dc1 = new DataColumn("prizename", typeof(string));
DataColumn dc2 = new DataColumn("point", typeof(int));
DataColumn dc3 = new DataColumn("number", typeof(int));
DataColumn dc4 = new DataColumn("totalpoint", typeof(int));
DataColumn dc5 = new DataColumn("prizeid", typeof(string));
dt.Columns.Add(dc1);
dt.Columns.Add(dc2);
dt.Columns.Add(dc3);
dt.Columns.Add(dc4);
dt.Columns.Add(dc5);
//以上代码完成了datatable的构架,但是里面是没有任何数据的
for (int i = 0; i < 10; i++)
{
DataRow dr = dt.NewRow();
dr["prizename"] = "娃娃" + i.ToString(); ;
dr["point"] = 10;
dr["number"] = i;
dr["totalpoint"] = 10;
dr["prizeid"] = "001";
dt.Rows.Add(dr);
}
return dt;
}
protected void giv_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
DataTable dt = GetTable();
int i = e.RowIndex;
dt.Rows[i].Delete();
dt.Rows.RemoveAt(i);
dt.AcceptChanges();
giv.DataSource = dt.DefaultView;
giv.DataBind();
}