<itemtemplate> <asp:CheckBox ID="chkStatus" runat="server" AutoPostBack="true" OnCheckedChanged="chkStatus_OnCheckedChanged" Checked='<%# Convert.ToBoolean(Eval("Activate")) %>' Text='<%# Eval("Activate").ToString().Equals("True") ? " Activate " : " Not Activate " %>' /> </itemtemplate>
In the aspx page for check box code as follows;
public void chkStatus_OnCheckedChanged(object sender, EventArgs e) { CheckBox chkStatus = (CheckBox)sender; GridViewRow row = (GridViewRow)chkStatus.NamingContainer; string vid = row.Cells[1].Text; bool status = chkStatus.Checked; string query = "UPDATE Vendors SET Activate = @Activate WHERE VendorId = @VendorId"; SqlConnection conn = new SqlConnection("Server=(local);initial catalog=master;Trusted_Connection=True"); SqlCommand com = new SqlCommand(query, conn); com.Parameters.Add("@Activate", SqlDbType.Bit).Value = status; com.Parameters.Add("@VendorId", SqlDbType.Bit).Value = vid; conn.Open(); com.ExecuteNonQuery(); conn.Close(); }
when i run the grid view it shows the error as follows Object cannot be cast from DBNull to other types. from my coding in the aspx and source page what is error please help me.