asp.net - can't trace e.NewValues at RowUpdating event of grid view -


i have problem grid view. have code grid view binding :

public void fillgrid1(string startalpha1, string columnname1, string searchtext1)     {         using (dataclassesdatacontext db = new dataclassesdatacontext())         {             var query = enumerable.repeat(new                 {                     id = default(int),                     reasontext = string.empty                 }, 0).tolist();             if (startalpha1 == "all")             {                 query = db.reasons.select(r => new { id = r.id, r.reasontext }).filterforcolumn(columnname1, searchtext1).tolist();             }             else             {                 query = db.reasons.select(r => new { id = r.id, r.reasontext }).filterforcolumn(columnname1, searchtext1).where(x => x.reasontext.startswith(startalpha1)).tolist();             }             dataset mydataset = new dataset();             datatable dt = new datatable();             dt.columns.add(new datacolumn("id", typeof(int)));             dt.columns.add(new datacolumn("reasontext", typeof(string)));             foreach (var item in query)             {                 if (item != null)                 {                     datarow dr = dt.newrow();                     dr["id"] = int.parse(item.id.tostring());                     dr["reasontext"] = item.reasontext.tostring();                     dt.rows.add(dr);                 }             }             mydataset.tables.add(dt);             lbl_count_reason.text = mydataset.tables[0].rows.count.tostring();             if (mydataset.tables[0].rows.count > 0)             {                 dataview mydataview = new dataview();                 mydataview = mydataset.tables[0].defaultview;                 if (this.viewstate["sortexp1"] != null)                 {                     mydataview.sort = this.viewstate["sortexp1"].tostring()                              + " " + this.viewstate["sortorder1"].tostring();                 }                 gv_viewreasons.datasource = mydataview;                 gv_viewreasons.databind();             }             else             {                 mydataset.tables[0].rows.add(mydataset.tables[0].newrow());                 gv_viewreasons.datasource = mydataset;                 gv_viewreasons.databind();                 int columncount = gv_viewreasons.rows[0].cells.count;                 gv_viewreasons.rows[0].cells.clear();                 gv_viewreasons.rows[0].cells.add(new tablecell());                 gv_viewreasons.rows[0].cells[0].columnspan = columncount;                 gv_viewreasons.rows[0].cells[0].text = "no records found";             }             if (gv_viewreasons.rows.count != 0)             {                 setpagenumbers1();             }         }     } 

and row updating event :

 protected void gv_viewreasons_rowupdating(object sender, gridviewupdateeventargs e)     {         int reasonid = convert.toint32(gv_viewreasons.datakeys[e.rowindex].value.tostring());         if (!string.isnullorempty(e.newvalues["reasontext"].tostring()))         {             using (dataclassesdatacontext db = new dataclassesdatacontext())             {                 db.updatereason(reasonid, e.newvalues["reasontext"].tostring().trim());                 db.submitchanges();                 gv_viewreasons.editindex = -1;                 this.fillgrid1((string)session["startalpha1"] ?? null, (string)session["columnname1"] ?? null, (string)session["searchtext1"] ?? null);                 updatepanel18.update();                 mpe1.show();             }         }     } 

here if (!string.isnullorempty(e.newvalues["reasontext"].tostring())) line throws object refrences not instance.... can't getting new value key.

how ever fillgrid1 have thid field. i'm going wrong here....

please me.....

because casting value of e.newvalues["reasontext"] string before check whether value null, need below:

    if(e.newvalues["reasontext"] != null &&           !string.isnullorempty(e.newvalues["reasontext"].tostring())) { //... } 

this check null value of e.newvalues["reasontext"] first , if not null go next condition.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -