Hi,
I've a gridview that has few fields, On btnSubmit click event I want the selected row cells to be inserted in my database.
protected void btnSubmit_Click(object sender, EventArgs e)
{
foreach (GridViewRow r in GridView1.Rows)
{
if (r.RowIndex == -1)
{
Response.Write("select a row");
}
else
{
string ProposalID = r.Cells[1].Text;
TextBox tb = (TextBox)r.FindControl("txtComments");
string comments = tb.Text;
TextBox t1 = (TextBox)r.FindControl("txtApprovedAmt");
string amount = t1.Text;
TextBox t2 = (TextBox)r.FindControl("txtDate");
string date = t2.Text;
DropDownList dd = (DropDownList)r.FindControl("dd_Recomm");
string recom = dd.SelectedItem.Text;
MyDataSet1TableAdapters.tbl_AssessmentTableAdapter ta = new MyDataSet1TableAdapters.tbl_AssessmentTableAdapter();
ta.sp_insertintoAssessment(recom, decimal.Parse(amount), comments, DateTime.Parse(date), int.Parse(ProposalID));
Response.Write("updated assessment");
}
}
}
But this code is accessing all the rows, I want to insert the items of only selected row