views:

375

answers:

1

I have an extended GridView class, GridViewEx, which inherits from the basic ASP.NET gridview. I override the CreateColumns method to intercept the columns collection and inject my own column, containing a modified CheckBoxField.

(Sidenote: I tried looking some other method of storing and updating which rows were selected and just using the checkbox as a display mechanism, but ultimately the checkbox was the easiest method for handling everything.)

The CheckBoxField has its ReadOnly property set to true when it is created (and it remains true when it is added to the columns collection), which should prevent it from being passed along as a parameter for Update requests against the gridview's datasource.

As you may infer, that's not happening. When I try to perform a row edit and update, I get a "Too many parameters" warning with a single parameter which has no name. If I turn off the multiselect function, this goes away. So I know that my checkboxfield is not being treated as a Readonly field. But I don't know how to fix it!

Any ideas on where, when, or how I need to set up this field so that it won't be passed automatically as a parameter to my updates?

A: 

Ok, figured it out.

I also had a custom CheckBoxField which overrides InitializeDataCell and writes in my own checkbox. I needed to add an extra check so that it disables the field during edits if Readonly is set. That seems to have resolved this issue. Hope this helps anyone else out who might be doing custom GridView edits.

    internal class InputCheckBoxField : CheckBoxField
    {
        //... Some boilerplate for ID and other properties here

        protected override void InitializeDataCell(DataControlFieldCell cell, DataControlRowState rowState)
        {
            base.InitializeDataCell(cell, rowState);

            if (cell.Controls.Count == 0)
            {
                CheckBox chk = new CheckBox();
                chk.ID = CheckBoxID;
                chk.AutoPostBack = true;
                cell.Controls.Add(chk);

                //This was the needed check
                if(ReadOnly && rowState == DataControlRowState.Edit)
                    chk.Enabled = false;
            }
        }
    }
CodexArcanum