Click here to Skip to main content
15,920,602 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello.

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


Any Help..
Posted
Updated 23-Jul-13 21:21pm
v3
Comments
Jameel VM 24-Jul-13 3:45am    
can you elaborate the question.
maye12 24-Jul-13 3:53am    
Their is a gridview in which i perform update and delete operations using datatable dynamically.
But that has to be done without using either sessions or viewstate.

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.
 
Share this answer
 
v2
Comments
maye12 24-Jul-13 4:32am    
Thanku so much for your quick response.But in your code session has been used.But that has to be achieved with out using sessions.
Chui PuiKwan 24-Jul-13 4:35am    
I update this code.

If you still hava any question or need any help,send message to me .
I am very happy to help you.
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900