Search code examples
c#asp.netcheckboxinsert-update

How to get selected value from checkbox in C#


I have the following line of code in insert.aspx.

Source Code:
 <asp:CheckBox ID="chkIncludeSignature" runat="server" Text="Include Signature" />

Code Behind:
 command1.Parameters.AddWithValue("?IncludeSignature", chkIncludeSignature.Checked ? 1 : 0);

And this is the code for update.aspx:

Source Code:
<asp:CheckBox ID="chkIncludeSignature" runat="server" Text="Include Signature" />

Code Behind:
 chkIncludeSignature.Checked=dtInvoice.Rows[0]["IncludeSignature"].ToString();

I have inserted the checkbox value in db Table. I want the selected value in update form that i have inserted in insert form.i am getting the error as "Cannot convert type string to bool".


Solution

  • chkIncludeSignature.Checked=dtInvoice.Rows[0]["IncludeSignature"] == 1 ? true : false;