Note that there are some explanatory texts on larger screens.

plurals
  1. POCatching null values on databinding
    primarykey
    data
    text
    <p>I have a dropdownlist that is populated from an SQL select statement. The select statement filters for items where the 'bit' is set to false and the items, although still in the database are hidden.</p> <p>My problem is; when an item is out of stock or hidden (bit = false) the user may still have items that are now hidden so it throws an error. How and where can I catch this, show the original item or set the value to default?</p> <pre><code>protected void GradeDropDownList_DataBinding (object sender, EventArgs e) { var ddl = (DropDownList)(sender); var a = ((Label)MyDetailsView.FindControl("GradeLabelEdit")).Text; a = a.Trim(); if (a != "") { ddl.SelectedValue = a; } } </code></pre> <p>The select statement;</p> <pre><code> &lt;asp:SqlDataSource ID="getGrade" runat="server" ConnectionString="&lt;%$ ConnectionStrings:CasesTimeConnection %&gt;" SelectCommand="SELECT [gradeID], [gradeText] FROM [user_grades] WHERE ([visibleState] = @visibleState)"&gt; &lt;SelectParameters&gt; &lt;asp:Parameter DefaultValue="True" Name="visibleState" Type="Boolean" /&gt; &lt;/SelectParameters&gt; &lt;/asp:SqlDataSource&gt; </code></pre> <p>In page;</p> <pre><code>&lt;EditItemTemplate&gt; &lt;asp:DropDownList ID="GradeDropDownList" runat="server" DataSourceID="getGrade" DataTextField="gradeText" DataValueField="gradeID" OnDataBinding="GradeDropDownList_DataBinding" OnSelectedIndexChanged="GradeDropDownList_SelectedIndexChanged"&gt; &lt;/asp:DropDownList&gt; &lt;/EditItemTemplate&gt; &lt;ItemTemplate&gt; &lt;asp:Label ID="gradeLabel" runat="server" Text='&lt;%# Bind("gradeText") %&gt;'&gt;&lt;/asp:Label&gt; &lt;/ItemTemplate&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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