3

I am gathering data and everything works, the check box is checked if the bit in the database is 1 and unchecked if it is null or 0.

However the check box seems disabled, I need the user to be able to check the box, which will update the database as well.

Here is my check box:

<Columns>
    <asp:CheckBoxField DataField="submitted" HeaderText="Submitted" ItemStyle-HorizontalAlign="Center" />
</Columns>

Am I missing something to make this check box clickable?

2 Answers 2

2

You need to place you're GridView in edit mode in order to check or uncheck the CheckBox. There are a few ways you can do this. This simplest is probably to add this property to your GridView markup:

AutoGenerateEditButton="True"

And then click the edit button that gets created in the row you want to modify.

You can place a specific row into edit mode via code-behind by setting the EditIndex of your GridView to the desired row index*:

yourGridViewID.EditIndex = 1;
yourGridViewID.Databind();

*I used "1" as an example above, but you can use any row index that's within the bounds of the GridView.Rows collection

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the help, I went a completely different method and used a button as all the frame work was already there to make adding a button quicker.
1

I think this link / quote from docs below might explain your problem.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.checkboxfield.aspx

A check box is disabled (read-only) until the data-bound control displays a record that contains the check box in edit mode. For more information on how to put a record into edit mode, see the documentation for the parent control that contains the CheckBoxField object.

See this post for the best way to handle this...

https://stackoverflow.com/a/1951150/1246574

EDIT

You're also missing runat="server" in your CheckBoxField code snippet that you posted.

2 Comments

You actually don't need runat="server" on these, since it is a sub-element of a server-side databound control (it's part of the GridView.Columns collection).
Thanks for the help, I went a completely different method and used a button as all the frame work was already there to make adding a button quicker.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.