i get a message that says "Index was outside the bounds of the array"
string Members = dt.Rows[0]["AssignedMembers"].ToString();
string[] splitMembers = Members.Split(',');
for (int i=0; i <cblMembersAssigned.Items.Count; i++)
{
if (cblMembersAssigned.Items[i].Text == splitMembers[i].ToString())
{
//if it's equal then check the items in the CHeckBox
cblMembersAssigned.Items[i].Selected = true;
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();
//Compare assigned members to database. check appropriate checkboxes
string Members = dt.Rows[0]["AssignedMembers"].ToString();
string[] splitMembers = Members.Split(',');
//for (int i=0; i <cblMembersAssigned.Items.Count; i++)
for (int i=0; i < splitMembers.Length; i++)
//if it's equal then check the items in the CHeckBox
//cblMembersAssigned.Items[i].Selected = true;
string strItem = splitMembers[i].ToString();cblMembersAssigned.Items.FindByText(strItem).Selected =
true;
string Members = dt.Rows[0]["AssignedMembers"].ToString();
string[] splitMembers = Members.Split(',');
for (int i =1; i <= splitMembers.Lenght ; i++)
{
kcrewjap
Member
15 Points
188 Posts
Re: Populate fields from dropdown selection
Jun 23, 2008 11:02 PM|LINK
i get a message that says "Index was outside the bounds of the array"
string Members = dt.Rows[0]["AssignedMembers"].ToString(); string[] splitMembers = Members.Split(','); for (int i=0; i <cblMembersAssigned.Items.Count; i++){
if (cblMembersAssigned.Items[i].Text == splitMembers[i].ToString()){
//if it's equal then check the items in the CHeckBox cblMembersAssigned.Items[i].Selected = true;}
}
vinz
All-Star
127077 Points
17946 Posts
MVP
Re: Populate fields from dropdown selection
Jun 24, 2008 12:01 PM|LINK
It seems that your CBL count doesn't match the the counts of the splited text that's why you get that exception.. anyway can you try this below
string Members = dt.Rows[0]["AssignedMembers"].ToString();
string[] splitMembers = Members.Split(',');
for (int i=0; i <splitMembers.Lenght ; i++)
{
string strItem = splitMembers[i].ToString();
CheckBoxList1.Items.FindByText(strItem).Selected = true;
}
MessageBox Controls for WebForms | Blog | Twitter | Linkedin
kcrewjap
Member
15 Points
188 Posts
Re: Populate fields from dropdown selection
Jun 24, 2008 04:23 PM|LINK
Object reference not set to an instance of an object. is the error i receive on this line
cblMembersAssigned.Items.FindByText(strItem).Selected =
true;vinz
All-Star
127077 Points
17946 Posts
MVP
Re: Populate fields from dropdown selection
Jun 24, 2008 04:28 PM|LINK
Post your current codes here
MessageBox Controls for WebForms | Blog | Twitter | Linkedin
kcrewjap
Member
15 Points
188 Posts
Re: Populate fields from dropdown selection
Jun 24, 2008 04:35 PM|LINK
{
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 string Members = dt.Rows[0]["AssignedMembers"].ToString(); string[] splitMembers = Members.Split(','); //for (int i=0; i <cblMembersAssigned.Items.Count; i++) for (int i=0; i < splitMembers.Length; i++){
//if (cblMembersAssigned.Items[i].Text == splitMembers[i].ToString()){
//if it's equal then check the items in the CHeckBox //cblMembersAssigned.Items[i].Selected = true; string strItem = splitMembers[i].ToString();cblMembersAssigned.Items.FindByText(strItem).Selected = true;}
}
}
vinz
All-Star
127077 Points
17946 Posts
MVP
Re: Populate fields from dropdown selection
Jun 24, 2008 05:03 PM|LINK
Try this way
string Members = dt.Rows[0]["AssignedMembers"].ToString();
string[] splitMembers = Members.Split(',');
for (int i =1; i <= splitMembers.Lenght ; i++)
{
string strItem = splitMembers[i].ToString();
if (int.Parse(strItem) == i)
{
CheckBoxList1.Items.FindByText(strItem).Selected = true;
}
}
MessageBox Controls for WebForms | Blog | Twitter | Linkedin
kcrewjap
Member
15 Points
188 Posts
Re: Populate fields from dropdown selection
Jun 24, 2008 05:08 PM|LINK
okay now the tool works, its just not checking the appropriate checkboxes. all other fields are populating except the cbl
when put break point around this and step through it, the values are correct.. its just not checking the boxes
vinz
All-Star
127077 Points
17946 Posts
MVP
Re: Populate fields from dropdown selection
Jun 24, 2008 05:22 PM|LINK
This line below should check the CBL items
CheckBoxList1.Items.FindByText(strItem).Selected = true;
MessageBox Controls for WebForms | Blog | Twitter | Linkedin
kcrewjap
Member
15 Points
188 Posts
Re: Populate fields from dropdown selection
Jun 24, 2008 05:28 PM|LINK
i know it should. just not understanding why its NOT checking the checkboxes. when i step through this code. the strItem is the coreect value..
kcrewjap
Member
15 Points
188 Posts
Re: Populate fields from dropdown selection
Jun 24, 2008 05:53 PM|LINK
jsut tryingto backtrack...so i have a table called tblAssignedMembers. this table contains a CheckboxId and CheckboxName
the CheckboxId is what is stored as a string in the tblAddProject table in the column called AssignedMembers
wondering if this is not matching that string value (example "5") to the checkboxId?