c# - how to get value from table in RowEditing -


i have grid view has columns id, f_name, l_name , salary. want value of grid view.

i have code can take mean:

    protected void page_load(object sender, eventargs e)     {         if (!page.ispostback)              bindgrideview();     }     protected void bindgrideview()     {         sqlconnection strcon1 = new sqlconnection(strcon);         strcon1.open();         string addstr = "select id,f_name , l_name , salary employee ";         sqlcommand addcmd = new sqlcommand(addstr, strcon1);         datatable table = new datatable();         sqldataadapter adapter = new sqldataadapter(addcmd);         adapter.fill(table);          gridview1.databind();      }     protected void gridview1_rowediting(object sender, gridviewediteventargs e)     {         int id= // must write here ?          gridview1.editindex = e.neweditindex;         bindgrideview();         sqlconnection strcon1 = new sqlconnection(strcon);         strcon1.open();         string addstr = "select id employee ";         sqlcommand addcmd = new sqlcommand(addstr, strcon1);         reademp(id);     }     public void reademp(int id)     {         sqlconnection strcon1 = new sqlconnection(strcon);         strcon1.open();         string addstr = "select id,f_name , l_name , salary , [department id]  ,  [saudi_nationality] , [position id]  , [role id] employee ";         sqlcommand addcmd = new sqlcommand(addstr, strcon1);         datatable table = new datatable();         sqldataadapter adapter = new sqldataadapter(addcmd);         adapter.fill(table);         gridview1.datasource = table;         gridview1.databind();         sqldatareader mydatareader;         mydatareader = addcmd.executereader();         mydatareader.read();          string f_name = mydatareader["f_name"].tostring();         string l_name = mydatareader["l_name"].tostring();         string department_id = mydatareader["[department id]"].tostring();         string saudi_nationality = mydatareader["saudi_nationality"].tostring();         string position_id = mydatareader["[position id]"].tostring();         string role_id = mydatareader["[role id]"].tostring();         mydatareader.close();      }      protected void button2_click(object sender, eventargs e)     {         string f_name = textbox1.text;         string l_name = textbox2.text;         string salary = textbox3.text;         int status = 1;          sqlconnection strcon1 = new sqlconnection(strcon);         strcon1.open();         string addstr = "addemployee";         sqlcommand addcmd = new sqlcommand(addstr, strcon1);         addcmd.commandtype = commandtype.storedprocedure;         addcmd.parameters.addwithvalue("@f_name", f_name);         addcmd.parameters.addwithvalue("@l_name", l_name);         addcmd.parameters.addwithvalue("@salary", salary);         addcmd.parameters.addwithvalue("@status", status);          addcmd.executenonquery();         bindgrideview();         textbox1.text = "";         textbox2.text = "";         textbox3.text = "";     } 

perhaps if associate datatable gridview..

protected void bindgrideview() {    .....    adapter.fill(table);    gridview1.datasource = table; // <- missing    gridview1.databind();    .... } 

then can read value of first cell in current row with

int id = convert.toint32(gridview1.rows[e.neweditindex].cells[0].text); 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

android - Keyboard hides my half of edit-text and button below it even in scroll view -