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:

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

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
        Else
            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?
pascalmartinAsked:
Who is Participating?
 
pascalmartinAuthor Commented:
Hi there I solve the issue on my own.
0
 
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

0
 
pascalmartinAuthor Commented:
Sorry Miguel this doesn't work, the procedure doesn't fire...
0
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
0
 
Miguel OzSoftware EngineerCommented:
No worries, please post your solution as the accepted answer and close the question.
0
 
pascalmartinAuthor Commented:
I solved it by myself after trying many different solutions...
0
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.