How to have checkbox as objectDataSource update parameter?
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" Property开发者_JAVA技巧Name="Checked" />
</UpdateParameters>
</asp:ObjectDataSource>
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.
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.
精彩评论