kaarthikeyan
kaarthikeyan

Reputation: 11

How to insert textbox values which is present in gridview

I have one gridview ,in that i'm using more than 5 textboxes in item template i want to insert the values present in textbox to table any body plz give your sugesstion

i tried the following method its showing error i write these lines in button click event

TextBox txtprod = (TextBox)sender;   
GridViewRow row = (GridViewRow)txtprod.Parent.Parent;  
int rowIndex = row.RowIndex;  
TextBox txtDetails
    =(TextBox)GridView2.Rows[rowIndex].Cells[1].FindControl("txtProd"); 
TextBox txtQuoQuantity=(TextBox)GridView2.Rows[rowIndex].Cells[3].FindControl("txtQuantity"); 
TextBox txtTax = (TextBox)GridView2.Rows[rowIndex].Cells[6].FindControl("txtTax");  
TextBox txtQuoRate = (TextBox)GridView2.Rows[rowIndex].Cells[4].FindControl("txtrate");  
TextBox txtQuoDis = (TextBox)GridView2.Rows[rowIndex].Cells[5].FindControl("txtDis"); 
TextBox txtQuoAmount = (TextBox)GridView2.Rows[rowIndex].Cells[7].FindControl("txtAmt");

Upvotes: 0

Views: 610

Answers (1)

KV Prajapati
KV Prajapati

Reputation: 94653

Steps:

  1. Traverse the Rows collection of GridView.
  2. Use FindControl method to get the reference of each TextBox in the Cells collection.
  3. Prepare the SQL - INSERT statement to insert a row via ADO.NET provider or use Entity framework.

Upvotes: 1

Related Questions