Really hope someone can help with this, as it is for a exam on monday! :)
I got a page, where there are 40 radio buttons:
My big problem is, how do i select the checked once, and insert them into database?
Nestedrepeater.aspx
__________
<%# DataBinder.Eval(Container.DataItem,"QuestionsName") %>
SelectedValue='<%# DataBinder.Eval(Container.DataItem, "[\"QuizAnswerid\"]")%>' runat="server" TextAlign="Right" />
Nedstedrepeater.aspx.cs
_______________________
using System;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace NestedRepeater
{
public partial class NestedRepeater : System.Web.UI.Page
{
public NestedRepeater()
{
Page.Init += new System.EventHandler(Page_Init);
}
public void Page_Load(object sender, EventArgs e)
{
//Create the connection and DataAdapter for the Authors table.
SqlConnection cnn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["QuizDataConnectionString1"].ConnectionString);
SqlDataAdapter cmd1 = new SqlDataAdapter("select * from Questions", cnn);
//Create and fill the DataSet.
DataSet ds = new DataSet();
cmd1.Fill(ds, "Questions");
//Create a second DataAdapter for the Titles table.
SqlDataAdapter cmd2 = new SqlDataAdapter("select * from QuizAnswers", cnn);
cmd2.Fill(ds, "QuizAnswers");
//Create the relation bewtween the Authors and Titles tables.
ds.Relations.Add("myrelation",
ds.Tables["Questions"].Columns["Questionsid"],
ds.Tables["QuizAnswers"].Columns["QuestionID"]);
//Bind the Authors table to the parent Repeater control, and call DataBind.
parentRepeater.DataSource = ds.Tables["Questions"];
Page.DataBind();
//Close the connection.
cnn.Close();
}
private void Page_Init(object sender, EventArgs e)
{
InitializeComponent();
}
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
// Event when button is cliced
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection cnn = new SqlConnection();
cnn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["QuizDataConnectionString1 "].ConnectionString;
cnn.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select * from Answers";
cmd.Connection = cnn;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds, " Answers ");
SqlCommandBuilder cb = new SqlCommandBuilder(da);
DataRow drow = ds.Tables["Answers"].NewRow();
drow["Name"] = Name.Text;
drow["Telephone"] = Telephone.Text;
drow["Email"] = Mail.Text;
// As you can see here, i got the field ready, just need to find the selected data to insert.
// As you can see here, i got the field ready, just need to find the selected data to insert.
drow["Qs1"] = TextBox1.Text;
drow["Qs2"] = TextBox1.Text;
drow["Qs3"] = TextBox1.Text;
drow["Qs4"] = TextBox1.Text;
drow["Qs5"] = TextBox1.Text;
drow["Qs6"] = TextBox1.Text;
drow["Qs7"] = TextBox1.Text;
drow["Qs8"] = TextBox1.Text;
drow["Qs9"] = TextBox1.Text;
drow["Qs10"] = TextBox1.Text;
drow["Total_Correct_Answers"] = TextBox1.Text;
ds.Tables["Answers "].Rows.Add(drow);
da.Update(ds, " Answers ");
string script = @"
alert('Information have been Saved Successfully.......!!!!!.');
;";
Page.ClientScript.RegisterStartupScript(this.GetType(), "myJScript1", script);
}
}
}
}
2 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Matias aabyePosted May 13, 2013, 1:33 AM
I've changed it all into RadioButtonList
Which works now.
But my main problem is now this:
I use this command to retrieve the data:
But how do i format that into a array, that i can put into my tabel?
Riddhi ValechaPosted May 13, 2013, 12:43 AM
Make use of RadioButtonList and add as many items as you want...
whether its 4 or 40 or 400 or 4000...