如何使用DataTable在gridview中执行编辑,删除,更新操作,而不使用Sessions或ViewState [英] How to Perform Edit,Delete,Update Operations in gridview using DataTable and without using Sessions or ViewState

查看:54
本文介绍了如何使用DataTable在gridview中执行编辑,删除,更新操作,而不使用Sessions或ViewState的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。



如何使用DataTable在GridView中执行编辑,删除,更新操作,而不使用Sessions或ViewState





任何帮助..

Hello.

How to Perform Edit,Delete,Update Operations in GridView using DataTable and without using Sessions or ViewState


Any Help..

推荐答案

你必须首先详细说明你的问题。



我想你想要实施一些操作。

请遵循以下代码:



//履行数据表

DataTable DT = new DataTable();

DT.Columns.Add(SubjectID,typeof(int));

DT .Columns.Add(School,typeof(string));

DT.Columns.Add(Grade,typeof(string));

DT.Columns .Add(Class,typeof(string));

DT.Columns.Add(Subject,typeof(string));

DT.Columns.Add (Edtion,typeof(string));





//更新数据表

DataTable mydt = DT;

DataRow dr = mydt.NewRow();

dr [SubjectID] = Convert.ToInt32(GridView1.DataKeys [i] .Value);

dr [School ] = ddlSchool.SelectedItem.Text;

dr [Grade] = ddlGrade.SelectedItem.Text;

dr [Class] = ddlClass.SelectedItem.Text;

dr [Subject] = GridView1.Rows [i] .Cells [3] .Text;

dr [Edtion] = GridView1.Rows [i] .Cells [4] .Text;

mydt.Rows.Add(dr);



GridView2.DataSource = mydt;

GridView2.DataBind ();



//删除

protected void GridView2_RowCommand(object sender,GridViewCommandEventArgs e)

{

int gvindex = Convert.ToInt32(e.CommandArgument); //获取gridview索引



DataTable mydt = DT;

尝试

{

DataRow [] drs = mydt.Select(" SubjectID =" + GridView2.DataKeys [gvindex] .Value.ToString()) ;

foreach(DataRow dr in drs)

{

dr.Delete();

}



}

catch(Exception ex)

{

抛出ex;

}

GridView2.DataSource = mydt;

GridView2.DataBind();

}



如果您有任何疑问,请发送邮件给我!我很乐意回复。
You must elaborate your question firstly.

I guess that you want to implement some operations.
Follow the following codes:

//fulfill datatable
DataTable DT = new DataTable();
DT.Columns.Add("SubjectID", typeof(int));
DT.Columns.Add("School", typeof(string));
DT.Columns.Add("Grade", typeof(string));
DT.Columns.Add("Class", typeof(string));
DT.Columns.Add("Subject", typeof(string));
DT.Columns.Add("Edtion", typeof(string));


//update datatable
DataTable mydt = DT;
DataRow dr = mydt.NewRow();
dr["SubjectID"] = Convert.ToInt32(GridView1.DataKeys[i].Value);
dr["School"] = ddlSchool.SelectedItem.Text;
dr["Grade"] = ddlGrade.SelectedItem.Text;
dr["Class"] = ddlClass.SelectedItem.Text;
dr["Subject"] = GridView1.Rows[i].Cells[3].Text;
dr["Edtion"] = GridView1.Rows[i].Cells[4].Text;
mydt.Rows.Add(dr);

GridView2.DataSource = mydt;
GridView2.DataBind();

//delete
protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e)
{
int gvindex = Convert.ToInt32(e.CommandArgument);//get gridview index

DataTable mydt = DT;
try
{
DataRow[] drs = mydt.Select("SubjectID=" + GridView2.DataKeys[gvindex].Value.ToString());
foreach (DataRow dr in drs)
{
dr.Delete();
}

}
catch(Exception ex)
{
throw ex;
}
GridView2.DataSource=mydt;
GridView2.DataBind();
}

If you hava any question,send message to me!And i am pleasure to reply it.


使用jQuery Grid插件,例如DataTable.js,jQGrid..etc,并将数据作为json加载到网格中



欲了解更多信息,请浏览此链接

使用ASMX Web服务的ASP.NET的JQGrid [ ^ ]



http://www.trirand.com/blog/?page_id= 6 [ ^ ]



希望这有助于
Use jQuery Grid plugin for example DataTable.js,jQGrid..etc and Load the data as json to the Grid

For more informations go through this links
JQGrid With ASP.NET Using ASMX Web Services[^]

http://www.trirand.com/blog/?page_id=6[^]

Hope this helps


这篇关于如何使用DataTable在gridview中执行编辑,删除,更新操作,而不使用Sessions或ViewState的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆