TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
kehinde adeoya
NA
2
12.4k
Get selected checkboxes
Mar 12 2012 12:16 PM
[code]
public void personPanel_Click(object sender, EventArgs e) { string DBConnection = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\LinksApplication.mdf;Integrated Security=True;User Instance=True"; SqlConnection sqlConnection = new SqlConnection(DBConnection); sqlConnection.Open(); try { SqlCommand sqlCommand = sqlConnection.CreateCommand(); sqlCommand.CommandText = "SELECT * FROM Person"; sqlCommand.CommandType = System.Data.CommandType.Text; SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand); DataSet dataSet = new DataSet(); sqlDataAdapter.Fill(dataSet, "Person"); DataTable dataTable = dataSet.Tables["Person"]; int rowsPerson = dataSet.Tables["Person"].Rows.Count; int count = 0; RadioButton[] personRadio = new RadioButton[rowsPerson]; foreach (DataRow dataRow in dataTable.Rows) { string strFirtsname = dataRow["firstname"].ToString(); string strLastname = dataRow["lastname"].ToString(); personRadio[count] = new RadioButton(); personRadio[count].Name = personRadio[count].ToString(); personRadio[count].Text = strFirtsname + " " + strLastname; personRadio[count].TabIndex = count; personRadio[count].Location = new Point(20, count * 20); personRadio[count].AutoCheck = true; personRadio[count].CheckedChanged += new EventHandler(personRadio_CheckChanged); personPanel.Controls.Add(personRadio[count]); personPanel.Visible = true; count++; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { sqlConnection.Close(); } } private void personRadio_CheckChanged(object sender, System.EventArgs e) { RadioButton personRadio = (RadioButton)sender; } //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ private void circumstancePanel_Click(object sender, EventArgs e) { string DBConnection = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\LinksApplication.mdf;Integrated Security=True;User Instance=True"; SqlConnection sqlConnection = new SqlConnection(DBConnection); try { sqlConnection.Open(); SqlCommand sqlCommand = sqlConnection.CreateCommand(); sqlCommand.CommandType = System.Data.CommandType.Text; sqlCommand.CommandText = "SELECT * FROM Circumstance"; SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand); DataSet dataSet = new DataSet(); sqlDataAdapter.Fill(dataSet, "Circumstance"); DataTable dataTable = dataSet.Tables["Circumstance"]; int rowCircumstance = dataSet.Tables["Circumstance"].Rows.Count; int count = 0; CheckBox[] checkCircumstance = new CheckBox[rowCircumstance]; foreach (DataRow dataRow in dataTable.Rows) { string strRole = dataRow["circumstance"].ToString(); checkCircumstance[count] = new CheckBox(); checkCircumstance[count].Name = checkCircumstance[count].ToString(); checkCircumstance[count].Text = strRole; checkCircumstance[count].TabIndex = count; checkCircumstance[count].Location = new Point(20, count * 20); checkCircumstance[count].AutoCheck = true; circumstancePanel.Controls.Add(checkCircumstance[count]); circumstancePanel.Visible = true; count++; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { sqlConnection.Close(); } } //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ private void linkUser_Click(object sender, EventArgs e) { if(personPanel.Controls!=null){ foreach(Control items in personPanel.Controls){ } if(circumstancePanel.Controls!=null){ foreach(Controls .........//How do i write the code for the selected checkbox(es) ){ } [/code]
Explain in bits what I want to achieve in this line of codes:
personPanel contains dynamically added radio buttons based on the number of items in the database table
circumstancePanel contains dynamically added checkboxes based on the number of items in the database table
Now I want to use linkUser_Click(sender, e) to achieve this:
When a personRadio (radio Button) is clicked on the interface of personPanel and many other checkboxes are checked in circumstancePanel i want it to work this way:
Anytime that the same radio button in personPanel interface is clicked it should display the checked checkbox as its assigned values. I have a panel I want to add this to already.
My immense appreciation goes beyond writing. Thanks. Gold bless in Jesus name.
Reply
Answers (
1
)
.Contains or delimeters
Property in the C#