Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 136,006 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 2,353 people online right now. Registration is fast and FREE... Join Now!




Checking Dynamic Checkboxes from database

 
Reply to this topicStart new topic

Checking Dynamic Checkboxes from database

dmxxmd
31 Mar, 2008 - 11:51 PM
Post #1

New D.I.C Head
*

Joined: 25 Oct, 2007
Posts: 25



Thanked: 1 times
My Contributions
Hi Everyone, wondered if you could give me some clues,

Im busy with a windows app now hey, and I got a form that looks like this.





If I dblClick on a record, it opens this page:







The 133 is the assessmentId of that record that Ive clicked on. And there is protocols on the left hand side as you can see 1 to 4.

Now If I click on protocols It checks the checkboxes and save it in the database as int_AssessmentId : 133 and the the protocols got values

Ex: 22 44 78 and 22



Now If I go out to the grid again and click on the same record I want it to check the items that I have checked before and It doesn’t..



Don’t u maybe have a clue how I can do that, I know that I might use a storedProc.

And the checkboxes is created Dynamically…



Thanx

















Attached File(s)
Attached File  dg.bmp ( 315.96k ) Number of downloads: 19
Attached File  Protocols.bmp ( 234.69k ) Number of downloads: 19
User is offlineProfile CardPM
+Quote Post

baavgai
RE: Checking Dynamic Checkboxes From Database
1 Apr, 2008 - 04:32 AM
Post #2

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 2,018



Thanked: 105 times
Dream Kudos: 475
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua

My Contributions
If you're using a DataTable for the grid source, pass the DataRow to the subform and have it work on that. Any changes should be reflected back since you're working on the same underlying data source.

If not, then when the sub form closes, ask it if any changes were made and manually update the grid data.

User is online!Profile CardPM
+Quote Post

dmxxmd
RE: Checking Dynamic Checkboxes From Database
3 Apr, 2008 - 09:40 PM
Post #3

New D.I.C Head
*

Joined: 25 Oct, 2007
Posts: 25



Thanked: 1 times
My Contributions
sorry bavgaai.

Here is my code

Thanx

csharp

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using Protocols;
using Assessments;


namespace SupplierAccreditation
{
public partial class frmSelectProtocols : Form
{
private Assessment assessment;
private NewAssessment newassessment;

private int assessmentId;
private int scheduleId;


public int AssessmentId
{
set { assessmentId = value; }
}

public int ScheduleId
{
set { scheduleId = value; }
}
private int statusId;

public int StatusId
{
set { statusId = value; }
}
private int supplierId;

public int SupplierId
{
set { supplierId = value; }
}

public frmSelectProtocols()
{
InitializeComponent();
}

private void frmSelectProtocols_Load(object sender, EventArgs e)
{

//lblAssess.Visible = false;
newassessment = new NewAssessment();
assessment = new Assessment();
DataSet dsGetAssessment = new DataSet();
DataSet dsGetSingleAssessment = new DataSet();
//KOMHIER

newassessment.ScheduleId = scheduleId;
newassessment.StatusId = statusId;
newassessment.SupplierId = supplierId;
assessment.InsertAssessment(newassessment);
//KOMHIER

dsGetSingleAssessment = assessment.GetSingleAssessment(scheduleId);
if (dsGetSingleAssessment.Tables[0].Rows.Count > 0)
{
DataTable tbl = dsGetSingleAssessment.Tables[0];
DataRow r = tbl.Rows[0];
lblAssess.Text = r["int_AssessmentId"].ToString();
}
else
{
dsGetAssessment = assessment.GetAssessment();
lblAssess.Text = dsGetAssessment.Tables[0].Rows[0]["int_AssessmentId"].ToString();
}

CheckBox chkCheck;

Protocol proto = new Protocol();
DataSet dsProtocols = new DataSet();

string previousprotocol = "";
string currentprotocol = "";

int y = 12;

dsProtocols = proto.GetProtocols();
for (int i = 0; i < dsProtocols.Tables[0].Rows.Count; i++)
{
chkCheck = new CheckBox();

currentprotocol = dsProtocols.Tables[0].Rows[i]["nv_ProtocolName"].ToString();

if (previousprotocol == "" || previousprotocol != currentprotocol)
{
chkCheck.Text = dsProtocols.Tables[0].Rows[i]["nv_ProtocolName"].ToString();
chkCheck.Location = new System.Drawing.Point(12, y);
chkCheck.Name = dsProtocols.Tables[0].Rows[i]["int_ProtocolId"].ToString();
chkCheck.CheckedChanged += new EventHandler(chkCheck_CheckedChanged);

this.Controls.Add(chkCheck);
chkCheck= null;
y += 20;

}
previousprotocol = currentprotocol;
//Selected Proto's--------------------------------------------------------------

Protocol protocol = new Protocol();
DataSet dsGetSelectedProtocols = new DataSet();
dsGetSelectedProtocols = protocol.GetSelectedProtocols(int.Parse(lblAssess.Text));

//MessageBox.Show(dsGetSelectedProtocols.Tables[0].Columns[0].ToString());


//Selected Proto's--------------------------------------------------------------
}
}

void chkCheck_CheckedChanged(object sender, EventArgs e)
{
SelectedProtocols selectedprotocols = new SelectedProtocols();
Protocol protocol = new Protocol();
DataSet dsProtocols = new DataSet();
dsProtocols = protocol.GetProtocols();

CheckBox chkCheck = new CheckBox();
chkCheck = (CheckBox)sender;

string chkname = chkCheck.Checked.ToString();

bool chkvalue = true;

if (chkname.Trim() != "")
{
selectedprotocols.ProtocolId = int.Parse(chkCheck.Name);

selectedprotocols.AssessmentId = int.Parse(lblAssess.Text);
selectedprotocols.ProtocolChecked = chkvalue;
//protocol.InsertSelectedProtocols(selectedprotocols);

}
else
{
DataSet dsGetSelectedProtocols = new DataSet();
dsGetSelectedProtocols = protocol.GetSelectedProtocols(int.Parse(lblAssess.Text));
if (chkname == dsGetSelectedProtocols.Tables[0].Rows[0].ToString())
{
chkCheck.Checked = true;
}
}
}


private void btnSubmit_Click(object sender, EventArgs e)
{
this.Close();
}
}
}


This post has been edited by PsychoCoder: 4 Apr, 2008 - 04:23 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 12:55PM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month