Join Dotnetcodes DotnetCodes.com is online Discussion Forum for Software professionals . It lets you find friends around the world and Create professional network that share similar interests as you. Get help on ur projects by industry specialists. Also get answers to all ur technical/placement related querries.Get an edge over others.
Already MemberClick here to login
ASP.net MVC Interview Questions Answers Interview Questions
Get Started Developing for Android Apps with Eclipse Articles
Whats New in ASP.NET 4.0 Part 2 Articles
.Net framework 4.0 Interview Questions Answers Interview Questions
SQL server reporting services Interview Questions (SSRS) part 1 Articles
SharePoint 2010 interview Questions Answers Interview Questions
Html5 interview questions and answers Interview Questions
Serial Number in SSRS Articles
How to Print a Crystal Report direct to printer Articles
Explaining SDLC -System Development Life Cycle Articles
Populate or bind Dropdownlist in Asp.net using Jquery and Json Articles
Sql Server Database Backup and Restore through C# Source Codes
ASP .Net Page Life cycle Articles
Benefits of Generics in .net Articles
.Net framework 4.0 major improvements Articles
Submit Articles | More Articles..

how to update particular cell in gridview datatable dynamically from textbox

Posted By: 9588 on 1/4/2013 6:52:22 AM | Comments:1 [Forward This]
public void BindData() { DataTable dt = new DataTable(); if (ViewState["datatab"] == null) { dt.Columns.Add("productid", typeof(string)); dt.Columns.Add("productname", typeof(string)); dt.Columns.Add("quantity", typeof(string)); DataRow dr = dt.NewRow(); //dr["productid"] = dt.Rows[0].ToString; dr["productid"] = TextBox2.Text; dr["productname"] = TextBox3.Text; dr["quantity"] = TextBox4.Text; dt.Rows.Add(dr); } else { dt = (DataTable)ViewState["datatab"]; //TextBox2.Text = GridView1.Rows[0].Cells[0].Text; //TextBox3.Text = GridView1.Rows[0].Cells[1].Text; //TextBox4.Text = GridView1.Rows[0].Cells[2].Text; //int rowIndex = 0; foreach (GridViewRow gvr in GridView1.Rows) //loop through GridView { //////quantity = Convert.ToInt32(TextBox4.Text); //TextBox4.Text = quantity.ToString(); // DataRow dr = dt.NewRow(); ////dr["productid"] = dt.Rows[0].ToString; // dr["productid"] = gvr.Cells[0].Text; //dr["productname"] =gvr.Cells[1].Text; //dr["quantity"] = gvr.Cells[2].Text; //dt.Rows.Add(dr); //GridView1.DataSource = dt; if (gvr.Cells[0].Text == TextBox2.Text & gvr.Cells[1].Text == TextBox3.Text) { ViewState["datatab"] = dt; int quantity = 0; //quantity = gvr.Cells[2].Text + TextBox4.Text ; quantity = Convert.ToInt32(TextBox4.Text); quantity = Convert.ToInt32(gvr.Cells[2].Text) + quantity; ////GridView1.DataSource = dt; //dt.Rows.Add(TextBox2.Text, TextBox3.Text, TextBox4.Text); //BindData(); //////dt.Rows[0]["quantity"] = quantity; //gvr.Cells[2].Text = quantity.ToString(); gvr.Cells[2].Text = quantity.ToString(); //dt.Rows[2].ItemArray = new object[] { "2" }; //dt.Rows[0].ItemArray[0] = "5"; for (int i = 0; i < dt.Rows[i].ItemArray ; i++) { DataRow myRow = dt.Rows[i]; dt.Rows[i]["quantity"] = quantity; for (int j = 0; j < dt.Columns[j].ColumnName; j++) { //quantity = Convert.ToInt32(gvr.Cells[2].Text) + quantity; if (dt.Columns[j].ColumnName.IndexOf("quantity") > 0) { quantity = Convert.ToInt32(dt.Rows[i][2].ToString()) + quantity; } //quantity = Convert.ToInt32(TextBox4.Text); //quantity = Convert.ToInt32(gvr.Cells[2].Text) + quantity; //quantity = Convert.ToInt32(dt.Rows[i][2].ToString()) + quantity; //quantity = Convert.ToInt32(dt.Rows[i][j].ToString()); //dt.Rows[i][2] = quantity; //dt.Rows.Add(TextBox2.Text, TextBox3.Text, gvr.Cells[2].Text); //quantity= Convert.ToInt32(gvr.Cells[i].Text); //dt.ColumnChanged += columnIndex.; // //dt.Rows.Add(gvr.Cells[2].Text); //dt.AcceptChanges(); //dt.Rows[i].SetField(column, value); //dt.Rows[i].SetField(2, value); //dt.Rows[i].SetField(quantity , value); ViewState["datatab"] = quantity.ToString(); //ViewState["datatab"] = dt; //GridView1.DataBind(); //GridView1.DataSource = dt; //GridView1.DataBind(); } } } else { if (gvr.Cells[0].Text == TextBox2.Text & gvr.Cells[1].Text == TextBox3.Text) { ViewState["datatab"] = dt; } else { } } } //dt.Rows.Add(TextBox2.Text, TextBox3.Text, TextBox4.Text); // if (( (TextBox1.Text) = dt.Columns[0].ColumnName.IndexOf("productid")) && ( (TextBox2.Text)=dt.Columns[1].ColumnName.IndexOf("productname") )) // { } // } // else // { // } //if (this.GridView1.RowCount == i) // break; //} for (int i = 0; i < dt.Rows.Count; i++) { if ((TextBox2.Text ==dt.Rows[i][0].ToString() ) & (TextBox3.Text == dt.Rows[i][1].ToString())) { } else { dt.Rows.Add(TextBox2.Text, TextBox3.Text, TextBox4.Text); } } ViewState["datatab"] = dt; GridView1.DataSource = dt; GridView1.DataBind(); //GridView1.DataSource = dt; //GridView1.DataBind(); }

Dear Friends, Dont forget to bookmark and submit your posting to social websites listed above.It will bring more visibility, buzz and fast action to attend your post

Responses to the Discussion: how to update particular cell in gridview datatable dynamically from textbox
Reply by: rakesh on: 1/5/2013 10:21:03 PM
Hi Krish, Thanks for posting on dotnetcodes.com. I think you already answered your question or you trying to post source code for your question. so, I suggest you to post your solved source code by selecting SUBMIT Articles menu (http://www.dotnetcodes.com/Code/frmPostCode.aspx) by doing this you will earn higher points of dotnetcodes.com. Please note that by selecting START DISCUSSIONS , you can ask questions.
 
You have not Logged In,  click here to Login
Reply Here
 
, I agree the terms and conditions of this website
  
Similar Discussion
SQl Server Integration Servers    Asked by: jakegeorge
show report header above the report parameters in report view using SSRS?    Asked by: mkhagat4u@gmail.com
how to convert sql data in dbf(foxpro) format using .net?    Asked by: mohitgupta186@gmail.com
how can run sql query in textbox?    Asked by: mohitgupta186@gmail.com
FILESTREAM IN C-SHARP    Asked by: stephen
Ask Questions | All Similar Discussions..
  .NET Framework
  ADO.NET
  AJAX
  Android
  ASP.NET
  ASP.NET AJAX
  ASP.NET MVC
  Azure
  Best Practices
  BizTalk Server
  C++
  CSharp
  CSS
  DBMS
  Error and Resolution
  HTML
  IIS
  JAVA
  JavaScript
  JQwery
  JSP
  LINQ
  Management
  Mobile
  ODP.NET
  OOPS
  Oracle
  Others
  Pattern and Practices
  PHP
  SAP
  SEO
  SharePoint
  Silverlight
  Sql Server
  SSAS
  SSIS
  SSRS
  UML
  UNIX
  VB
  VB.NET
  VS 2010
  WCF
  Web Analytics
  Windows Forms
  WPF
  WWF
  XML
  XSLT
  .NET Framework
  ADO.NET
  AJAX
  Android
  ASP.NET
  ASP.NET AJAX
  ASP.NET MVC
  Azure
  Best Practices
  BizTalk Server
  C++
  CSharp
  CSS
  DBMS
  Error and Resolution
  HTML
  IIS
  JAVA
  JavaScript
  JQwery
  JSP
  LINQ
  Management
  Mobile
  ODP.NET
  OOPS
  Oracle
  Others
  Pattern and Practices
  PHP
  SAP
  SEO
  SharePoint
  Silverlight
  Sql Server
  SSAS
  SSIS
  SSRS
  UML
  UNIX
  VB
  VB.NET
  VS 2010
  WCF
  Web Analytics
  Windows Forms
  WPF
  WWF
  XML
  XSLT
All rights reserved to dotnetcodes. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks.
Best viewed at 1024 x 768 resolution with Internet Explorer 5.0 or Mozila Firefox 3.5 or Google Crome and higher