Dynamic checkboxlist

Posted by Steve on Stack Overflow See other posts from Stack Overflow or by Steve
Published on 2011-01-06T10:51:43Z Indexed on 2011/01/06 10:53 UTC
Read the original article Hit count: 320

Filed under:
|

Hi,

I am currently building a dynamic url tab system that user can say what urls they want to be displayed on a tabpage control.

In the database i have the following columns.

userID, int URLName var Enabled bit

I am pulling the data back ok but what i am trying do is populate a checkbox list with the urlname and its status on a user options page so they can say what tabs they want displayed.

I have wrote the following methods to get the urls and create the checkboxes however i keep getting the following error.

ex = {"InvalidArgument=Value of '1' is not valid for 'index'.\r\nParameter name: index"}

It reads the first row ok but when it hits the 2nd row that is being returned i get that error.

Has anyone got any ideas?

Thanks

private void GetUserURLS()
    {

        db.initiateCommand("[Settings].[LoadAllUserURLS]", CommandType.StoredProcedure);

        sqlp = db.addParameter("@UserID", _UserID, SqlDbType.Int, ParameterDirection.Input);
        sqlp = db.addParameter("@spErrorID", DBNull.Value, SqlDbType.Int, ParameterDirection.InputOutput);

        db.executeCommand();

        CreateCheckBoxes(db.getTable(0).Rows);
        db.releaseCommand();
    }


    private void CreateCheckBoxes(DataRowCollection rows)
    {
        try
        {
            int i = 0;
            foreach (DataRow row in rows)
            {
                //Gets the url name and path when the status is enabled. The status of Enabled / Disabled is setup in the users option page
                string URLName = row["URLName"].ToString();
                bool enabled = Convert.ToBoolean(row["Enabled"]);

                CheckedListBox CB = new CheckedListBox();              
                CB.Items.Insert(i, URLName);

                CB.Tag = "CB" + i.ToString();

                checkedListBox1.Items.Add(CB);

                i++;
            }
        }

        catch (Exception ex)
        {
            //Log error
            Functionality func = new Functionality();
            func.LogError(ex);

            //Error message the user will see
            string FriendlyError = "There has been populating checkboxes with the urls - A notification has been sent to development";
            Classes.ShowMessageBox.MsgBox(FriendlyError, "There has been an Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }

© Stack Overflow or respective owner

Related posts about dynamic

Related posts about checkboxlist