c# - how can i get the value of the specific column of a table? -


how can read value every row of specific column?

i have table shown here table image, want model name "model" column , have database , "select" query behind depending on "model" shown, show quantity of "model" can me?

here sample code of .cs

 foreach (gridviewrow row in gv1.rows)         {              for(int = 0; i<gv1.columns.count;i++)             {                 string model = row.cells[i].text;                 string quan = row.cells[3].text;                 string ams = row.cells[4].text;              }         } 

note:-

  • data shown in table in database.
  • i have 2 seperate view tables models , quantity.

if understand want it's not best approach, try you. in opinion have quantity value before display of datatable, inside datatable, anyway think type of code requested :

//my datatable test , 3 columns         datatable dt = new datatable();         dt.columns.add("model");         dt.columns.add("other");         dt.columns.add("quantityfromdb");          //add  test data in datatable         for(int i=0;i<15;i++)         {             datarow dr = dt.newrow();             dr[0] = i*2+"";             dr[1] = "xx data xx";             dt.rows.add(dr);         }       //foreach row in datatable ( data )     for(int y=0;y<dt.rows.count;y++)         {             //get value of current "model" column value             string currentmodel = dt.rows[y]["model"].tostring();              //make request in db quantity             int quantityfromdb = 50; //request              //update value of quantityfromdb column model row             dt.rows[y]["quantityfromdb"] = quantityfromdb;         } 

you read value of specific row, , edit value of it's other column.

edit :

if want work directly on gridview, can moove code in row_databound event of gridview. see doc : https://msdn.microsoft.com/fr-fr/library/system.web.ui.webcontrols.gridview.rowdatabound(v=vs.110).aspx


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -