2011-10-10 39 views
0

我有一個gridview,因爲我在項目模板中使用超過5個文本框我想插入文本框中存在的值到表任何主體plz給你的sugesstion如何插入在gridview中存在的文本框的值

我嘗試以下方法其示出錯誤我寫在按鈕點擊事件

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"); 

回答

1

步驟這些行:

  1. 遍歷Rows集合GridView
  2. 使用FindControl方法獲取Cells集合中每個TextBox的引用。
  3. 通過ADO.NET provider準備SQL - INSERT語句插入行或使用Entity framework.
+0

亞我試圖FindControl方法其示值誤差,供您參考這裏我貼我的代碼 – kaarthikeyan

相關問題