1

In ObjectDataSource my checkbox is always ignored. My update method always receives NULL. What am I doing wrong here?

Thanks.

<asp:CheckBox ID="CheckBoxSort" runat="server" Checked="true" />

CheckBox is on its own. It is not contained in any other .net controls. ....

<asp:ObjectDataSource ID="odsProfileItems" runat="server" SelectMethod="GetProfileItemsForCategory" TypeName="Valero.WEB.BO.StoreProfile.ProfileItemService"             UpdateMethod="UpdateProfileItem">
    <SelectParameters>
        <asp:Parameter Name="CategoryID" Type="Int32" />
    </SelectParameters>
    <UpdateParameters>
        <asp:ControlParameter Name="IsSorting" ControlID="CheckBoxSort" PropertyName="Checked" />
    </UpdateParameters>
</asp:ObjectDataSource>

2 Answers 2

3

When using a CheckBox control with an Object Data Source, the value to pass to the wired up 'Update' method needs to be of type Boolean. I do this often, take a look to my code:

 <UpdateParameters>
       <asp:Parameter Name="IsAdminUser" Type="Boolean" />
       <asp:Parameter Name="IsPowerUser" Type="Boolean" />  
 </UpdateParameters>

Now just to show you as well, here is how I am binding the CheckBox on the page with data from the 'Select':

<asp:CheckBox ID="chkIsAdmin" runat="server" Checked='<%# Bind("IsAdminUser") %>' />

This checkbox control happens to be within a GridView, and the GridView's datasource is the Object Data Source control, so that is where data is bound. No matter if you are using a GridView or any other control such as a plain checkbox box, you should be able to use the format above to get the checkbox bound and updated properly.

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

3 Comments

Did you try the code I presented? Are you using a Boolean value?
Thank you. This works great. I didn't even know that Binding this way is possible. I accepted it as an answer. But, still, is there any good explanation why my code doesn't work?
No I have never tried wiring in the ControlID directly into the UpdateParameter, and not sure if the 'Checked' propertyname works well (obviously not). Checkboxes exhibit some odd behavior sometimes and I belive that to be the best working solution.
0

Have you tried to findout the Checkbox control ID from the HTML page rendered. Sometimes if you use master page it may change the controlId.

2 Comments

Sure, master page will change client ID. But here I am dealing with server side IDs. So client IDs don't matter. I generally think that something is wrong with wizard for ObjectDataSource...
I think the client controlId matters. May be you can try to check the controlId once for debugging purpose. If it is not working then something wrong with ObjectdataSource. That we have to figure out.

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.