Stored Proc. checkbox parameter in gridview

I have an editable gridview with a checkbox used to put a product in "Active" or "Inactive" mode.
The DB fields is a BIT type value.
When I try to update my gridview the checkbox does not update the field value??
Here is my code in the gridview:

<ItemTemplate><%#IIf(Eval("Active"), "<font color='lime'><i>Yes</i></font>", "<font color='red'><i>No</i></font>")%></ItemTemplate>
<asp:CheckBox ID="chk1" runat="server" Width="40px" Text='<%# ReplaceBoolValue(Eval("Active"))%>' Checked='<%# Eval("Active") %>' EnableViewState="true" />

Here is my parameter in code behind:

 myCom.Parameters.AddWithValue("@Active", SqlDbType.Bit)
        If CType(GridProducts.Rows(e.RowIndex).FindControl("chk1"), CheckBox).Checked = True Then
            myCom.Parameters("@Active").Value = 1
            myCom.Parameters("@Active").Value = 0
        End If

All other control inthe gridview are returning the correct values, except this checkbox.
Can you tell me what is wrong with my code?
Who is Participating?
pascalmartinAuthor Commented:
Hi there I solve the issue on my own.
Miguel OzSoftware EngineerCommented:
From memory, you need to compare the value returned from function Eval. (The return value could not be used as Boolean variable)
Replace  Eval("Active") with:
Eval("Active").ToString() == "1"

Open in new window

pascalmartinAuthor Commented:
Sorry Miguel this doesn't work, the procedure doesn't fire...
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Miguel OzSoftware EngineerCommented:
What is the value  of CType(GridProducts.Rows(e.RowIndex).FindControl("chk1"), CheckBox).Checked ? When the UI Checkbox is checked and when it is not.
Grvidview is very sensitive to where in the page lifecycle you are getting information. Could you post your complete page or a sample page with just your issue. I have VS2013/2010 and SQL server 2012
Miguel OzSoftware EngineerCommented:
No worries, please post your solution as the accepted answer and close the question.
pascalmartinAuthor Commented:
I solved it by myself after trying many different solutions...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.