Guys i have a grid and need to retrieve text inputs from and then insert to the the database . The grid looks like below
From the above it permits user to pass as many rows to the database as he so desired. i use the method below.
private void insert()
{
connection.Open();
for(int i=0; i< gvAdditionalDetails.Rows.Count ; i++)
{
string sql = "insert into [CONTACT_DETAILS] (type,description,contactID) VAlUES (@row1,@row2,@contactID )";
SqlCommand cmd = new SqlCommand(sql, connection);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@row1", gvAdditionalDetails.Rows[i].Cells[1].Text.Trim());
cmd.Parameters.AddWithValue("@row2", gvAdditionalDetails.Rows[i].Cells[2].Text.Trim());
cmd.Parameters.AddWithValue("@contactID", 39);
cmd.ExecuteNonQuery();
}
connection.Close();
}
The above method loop throw my grid , how ever is returning null for the columns type which has a dropdown selection and description which has a tetxbox control. I cant call this controls invidually because they are declared in a grid. How do i retrieve the text the selected item from the dropdown and the inserted text from the textbox. the code gvAdditionalDetails.Rows[i].Cells[1].Text.Trim()
returns null.