hello,
You can save your data in a seperate table via GridView's RowCommand Event.
Database structure :
--------------------
Table Questions : qid (PK), question
Table Answers : aid (PK), qid (FK), Answer
You have 3 columns in your GridView
1. Question Column i.e. TemplateField containing a Label
2. Answer Column i.e. TemplateField containing a TextBox
3. The third column is also a TemplateField containing a Button
The button's CommandArgumen is set to the Question Id (qid) in order
save the data with QuestionId in a referencing Answer Table
here is the code for PageLoad event (bind you r grid) :
if (!IsPostBack)
{
string Query = "SELECT * FROM Questions";
SqlCommand cmd = new SqlCommand(Query, CreateConnection());
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
here is the code for you saving of data i.e. RowCommand event of the GridView:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
string arg = e.CommandArgument.ToString();
GridViewRow row = (GridViewRow)((Button)e.CommandSource).NamingContainer;
TextBox MyAnswer = (TextBox)row.FindControl("txtAnswer");
string SaveAnswerQuery = "INSERT INTO Answers(qid,Answer) VALUES(" + arg + ",'" + MyAnswer.Text + "')";
}