Determine Empty Checkbox List

S

Stuart Shay

Hello All

I have a ASP.NET 2.0 checkbox list, the problem is when 0 items are checked
I am unable to determine if the list is empty


//Determine Checked Roles
CheckBoxList ckUserRoleList =
gvUserList.Rows[e.RowIndex].FindControl("ckUserRoleList") as CheckBoxList;
StringBuilder oStringBuilder = new StringBuilder();
foreach (ListItem li in ckUserRoleList.Items)
{
if (li.Selected == true) {
oStringBuilder.AppendFormat("{0},", li.Text);
}
}


if (oStringBuilder.Length != 0)
oStringBuilder.Remove(oStringBuilder.Length - 1, 1);

string[]userRoleList = (oStringBuilder.ToString().Split(new char[]
{','}));


/**** Empty Values are NOT Correctly Evaluated ****/

//Add New Roles for Selected User
if (userRoleList.Length != 0)
{
Roles.AddUserToRoles(userName, userRoleList);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top