okay.. now it succeeds when i build it. however im not sure the whole item.add is the right choice here as when i run the tool im building and select a projectname from the dropdown. everything is populated accept i the cbl, it adds another checkbox with
the values from teh database (i.e. 1, 3, 4, 5 ,6) instead of checking the boxes..
is cblMembersAssigned.Items.Add(dt.Rows[0]["AssignedMembers"].ToString()); correct? or should this line be taken out since we are using the for loop?
I think I'm lost here.. Actually I'm confused.. Does your CheckBoxList has already a values in it? Cause if it does not then you can't compare anything from your CBL.. But if your CBL has already an items on it then you can remove this line below and compare
it directly to the values of database and do the checking after..
SqlConnection conn =
new SqlConnection(Conn.CLNXCnnString());
conn.Open();
string sql = "select * from tblAddProject where ProjectName='" + strProjectName +
"'";
SqlCommand cmd =
new SqlCommand(sql, conn);
SqlDataAdapter da =
new SqlDataAdapter(cmd);DataTable dt =
new DataTable();
vinz
All-Star
127087 Points
17946 Posts
MVP
Re: Populate fields from dropdown selection
Jun 23, 2008 08:56 PM|LINK
Yes for as long as you enclose it with double quotes..
MessageBox Controls for WebForms | Blog | Twitter | Linkedin
kcrewjap
Member
15 Points
188 Posts
Re: Populate fields from dropdown selection
Jun 23, 2008 09:01 PM|LINK
Cannot implicitly convert type 'string' to 'bool' ???
if
(cblMembersAssigned.Items[i].Text = "1, 2, 3, 4, 5, 6")vinz
All-Star
127087 Points
17946 Posts
MVP
Re: Populate fields from dropdown selection
Jun 23, 2008 09:12 PM|LINK
My bad.. you need to use == signs when comparing two string values .. so have it this way below
if (cblMembersAssigned.Items[i].Text == "1, 2, 3, 4, 5, 6")
{}
MessageBox Controls for WebForms | Blog | Twitter | Linkedin
kcrewjap
Member
15 Points
188 Posts
Re: Populate fields from dropdown selection
Jun 23, 2008 09:16 PM|LINK
okay.. now it succeeds when i build it. however im not sure the whole item.add is the right choice here as when i run the tool im building and select a projectname from the dropdown. everything is populated accept i the cbl, it adds another checkbox with the values from teh database (i.e. 1, 3, 4, 5 ,6) instead of checking the boxes..
is cblMembersAssigned.Items.Add(dt.Rows[0]["AssignedMembers"].ToString()); correct? or should this line be taken out since we are using the for loop?
vinz
All-Star
127087 Points
17946 Posts
MVP
Re: Populate fields from dropdown selection
Jun 23, 2008 09:31 PM|LINK
I think I'm lost here.. Actually I'm confused.. Does your CheckBoxList has already a values in it? Cause if it does not then you can't compare anything from your CBL.. But if your CBL has already an items on it then you can remove this line below and compare it directly to the values of database and do the checking after..
cblMembersAssigned.Items.Add(dt.Rows[0]["AssignedMembers"].ToString());
MessageBox Controls for WebForms | Blog | Twitter | Linkedin
kcrewjap
Member
15 Points
188 Posts
Re: Populate fields from dropdown selection
Jun 23, 2008 09:32 PM|LINK
oh im sorry.. yes. my cbl already has 6 static checkboxes in it. each is a name of the member, so i dont need to add anymore.. does that help?
vinz
All-Star
127087 Points
17946 Posts
MVP
Re: Populate fields from dropdown selection
Jun 23, 2008 09:42 PM|LINK
MessageBox Controls for WebForms | Blog | Twitter | Linkedin
kcrewjap
Member
15 Points
188 Posts
Re: Populate fields from dropdown selection
Jun 23, 2008 09:44 PM|LINK
so once you do the comparison. how do you make the checkboxes either be checked or unchecked? right nwo the code looks like this:
protected void ddlSearch_SelectedIndexChanged(object sender, EventArgs e){
FillProjectFields(ddlSearch.SelectedValue);
}
private void FillProjectFields(string strProjectName){
SqlConnection conn = new SqlConnection(Conn.CLNXCnnString());conn.Open();
string sql = "select * from tblAddProject where ProjectName='" + strProjectName + "'"; SqlCommand cmd = new SqlCommand(sql, conn); SqlDataAdapter da = new SqlDataAdapter(cmd);DataTable dt = new DataTable();da.Fill(dt);
if (dt.Rows.Count > 0){
txtDate.Text = dt.Rows[0][
"RequestDate"].ToString(); txtChangeUser.Text = dt.Rows[0]["NTLogin"].ToString();txtProjectName.Text = dt.Rows[0][
"ProjectName"].ToString(); txtProjectDesc.Text = dt.Rows[0]["ProjectDesc"].ToString();ddlOccurrence.Items.Add(dt.Rows[0][
"Occurrence"].ToString()); if(dt.Rows[0]["Occurrence"].ToString() == "Reoccurring"){
ddlOccurrence.SelectedValue = "Reoccurring";}
else if (dt.Rows[0]["Occurrence"].ToString() == "One Time"){
ddlOccurrence.SelectedValue = "One Time";}
rblOccurrance.Items.Add(dt.Rows[0]["Automated"].ToString());rblOccurrance.Items.Add(dt.Rows[0][
"Manual"].ToString()); ddlStatus.Items.Add(dt.Rows[0]["StatusName"].ToString());if (dt.Rows[0]["StatusName"].ToString() == "New"){
ddlStatus.SelectedValue = "New";}
else if (dt.Rows[0]["StatusName"].ToString() == "Assigned"){
ddlStatus.SelectedValue = "Assigned";}
else if (dt.Rows[0]["StatusName"].ToString() == "Complete"){
ddlStatus.SelectedValue = "Complete";}
//cblMembersAssigned.Items.Add(dt.Rows[0]["AssignedMembers"].ToString()); txtCompletionDate.Text = dt.Rows[0]["CompletionDate"].ToString();}
conn.Close();
//Compare assigned members to database. check appropriate checkboxes for (int i=0; i <cblMembersAssigned.Items.Count; i++){
if (cblMembersAssigned.Items[i].Text == "1, 2, 3, 4, 5, 6"){
//if it's equal then check the items in the CHeckBox cblMembersAssigned.Items[i].Selected = true;}
}
}
kcrewjap
Member
15 Points
188 Posts
Re: Populate fields from dropdown selection
Jun 23, 2008 10:31 PM|LINK
also. shoudl i use the split function since the data comming from the database column is comma delimited? if so where?
vinz
All-Star
127087 Points
17946 Posts
MVP
Re: Populate fields from dropdown selection
Jun 23, 2008 10:46 PM|LINK
Try this
string member = dt.Rows[0]["AssignedMembers"].ToString();
string[] splitMember = member.Split(',');
for (int i=0; i <cblMembersAssigned.Items.Count; i++)
{
if (cblMembersAssigned.Items[i].Text == splitMember[i].ToString())
{
cblMembersAssigned.Items[i].Selected = true;
}
}
MessageBox Controls for WebForms | Blog | Twitter | Linkedin