Note that there are some explanatory texts on larger screens.

plurals
  1. POBinding for custom control works in GridView but not in FormView
    primarykey
    data
    text
    <p>I am turning some paper forms into web forms, and one of my requirements is to have a Yes/No group of checkboxs that can also track if no selection has been made. So I can't just use a single CheckBox bound to a bit field in Sql Server because that doesn't track whether the user has ignored the field or not.</p> <p>To solve my problem I wrapped two checkboxes into an ASCX control. I then created a public Checked property in my ASCX control. From this property I returned "True" if the true checkbox was checked, "False" is the false checkbox was checked, and an empty string if neither checkbox was checked.</p> <p>When I put this control in a GridView and bind it to a bit field using the GridView SqlDataSource everything works perfectly. When I bind the same control in a FormView though the FormView's update sets untouched controls to False. I stepped through my controls logic and it is passing the empty string correctly, so it seems that the FormView is overriding the value before sending it to the stored procedure.</p> <p>Is there a way to make this work in the FormView or am I going to have to refactor to use something like an int field to track the three options: 0=no selection, 1=true, 2=false, or something like that? I've provided the code for my ASCX control below for reference.</p> <pre><code>public partial class controls_yesNoCheck : System.Web.UI.UserControl { public string Checked { get { if (ckbNo.Checked) return "false"; if (ckbYes.Checked) return "true"; else return ""; } set { if (value == "") { ckbNo.Checked = false; ckbYes.Checked = false; } else if (value == "True" || value == "true") { ckbYes.Checked = true; ckbNo.Checked = false; } else { ckbNo.Checked = true; ckbYes.Checked = false; } } } protected void Page_Load(object sender, EventArgs e) { } protected void noChecked(object sender, EventArgs e) { ckbYes.Checked = false; } protected void yesChecked(object sender, EventArgs e) { ckbNo.Checked = false; } } </code></pre> <p>Edit: The front-end of the control looks so, I left the CheckChanged methods out of the previous code block since their functionality doesn't impact this problem.</p> <pre><code>&lt;%@ Control Language="C#" AutoEventWireup="true" CodeFile="yesNoCheck.ascx.cs" Inherits="controls_yesNoCheck" %&gt; &lt;asp:CheckBox ID="ckbYes" runat="server" Text="Yes" AutoPostBack="true" OnCheckedChanged="yesChecked" /&gt; &lt;asp:CheckBox ID="ckbNo" runat="server" Text="No" AutoPostBack="true" OnCheckedChanged="noChecked" /&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload