c# - Gridview remove selected row -


i want remove selected gridview row when updating don't know how it.

my update code:

    //update selected assignment     protected void buttonupdateassignmentclick(object sender, eventargs e)     {                    try         {             using (var db = new knowitcvdbentities())             {                 spweb thesite = spcontrol.getcontextweb(context);                 spuser theuser = thesite.currentuser;                 string strusername = theuser.loginname;                  var theemplassignment = (                                                 p                                                     in db.employees                                                 p.username == strusername                                                 select p).firstordefault();                  _emp = theemplassignment;                  if (_emp != null)                 {                     int assignmentid = convert.toint32(hiddenfield_assignment_id.value);                      var theemplassignmentname =                                                 (from p in db.employees_assignment                                                  p.employee_id == _emp.employee_id && p.assignment_id == assignmentid                                                  select p).first();                      if (theemplassignmentname != null)                     {                         theemplassignmentname.company_name = textboxcompanyname.text;                         theemplassignmentname.sector = textboxsector.text;                         theemplassignmentname.area = textboxarea.text;                         theemplassignmentname.from_date = textboxfromdate.text;                         theemplassignmentname.to_date = textboxtodate.text;                         theemplassignmentname.reference_name = textboxreference.text;                         theemplassignmentname.description = textboxdesc.text;                          db.savechanges();                          //populate gridview                          if (session["datatableassignment"] != null)                         {                             _dt = (datatable)session["datatableassignment"];                         }                         else                         {                             _dt.columns.add("company name");                             _dt.columns.add("sector");                             _dt.columns.add("area");                             _dt.columns.add("from");                             _dt.columns.add("to");                             _dt.columns.add("tools");                             _dt.columns.add("technology");                             _dt.columns.add("description");                             _dt.columns.add("reference");                             _dt.columns.add("assignmentid");                         }                         //dt.rows.clear();                          datarow dr = _dt.newrow();                         dr["company name"] = theemplassignmentname.company_name;                         dr["sector"] = theemplassignmentname.sector;                         dr["area"] = theemplassignmentname.area;                         dr["from"] = theemplassignmentname.from_date;                         dr["to"] = theemplassignmentname.to_date;                         dr["description"] = theemplassignmentname.description;                         dr["reference"] = theemplassignmentname.reference_name;                         dr["assignmentid"] = theemplassignmentname.assignment_id;                          list<assignment_tools> assignmenttools = (from p in db.assignment_tools                                                                                                                                         p.employee_id == _emp.employee_id &&                                                                       p.assignment_id == assignmentid                                                                   select p).tolist();                          string stoolvalue = string.empty;                         foreach (var vtool in assignmenttools)                         {                             stoolvalue += vtool.tool_name + ", ";                         }                         dr["tools"] = stoolvalue;                           list<assignment_technology> assignmenttech = (from p in db.assignment_technology                                                                                                                                                 p.employee_id == _emp.employee_id &&                                                                           p.assignment_id == assignmentid                                                                       select p).tolist();                          string stechvalue = string.empty;                         foreach (var vtech in assignmenttech)                         {                             stechvalue += vtech.technology_name + ", ";                         }                         dr["technology"] = stechvalue;                          _dt.rows.add(dr);                         session["datatableassignment"] = _dt;                          gridviewshowassignments.datasource = _dt;                         gridviewshowassignments.databind();                          textboxcompanyname.text = string.empty;                         textboxsector.text = string.empty;                         textboxarea.text = string.empty;                         textboxfromdate.text = string.empty;                         textboxtodate.text = string.empty;                         textboxdesc.text = string.empty;                         textboxreference.text = string.empty;                         listboxassignmenttools.items.clear();                         listboxassignmenttechnology.items.clear();                     }                 }             }         }         catch (exception x)         {             labelprovassignment.text = x.message;         }     } 

right got 1 assignment , want edit it, click on edit, enter new values , click on update: enter image description here

but when update finished following shown: enter image description here

problem in code adding new row in datatable.

 datarow dr = _dt.newrow(); 

enter image description here

it creating problem when taking table session . need delete specific row dt before rebinding gridview

  if (session["datatableassignment"] != null)  {      _dt = (datatable)session["datatableassignment"];                           datarow row = _dt.select("the condition")       _dt.rows.remove(row);    } 

i hope you.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -