开发者

Catching null values on databinding

开发者 https://www.devze.com 2023-03-30 02:51 出处:网络
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.

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.

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?

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; }
}

The select statement;

    <asp:SqlDataSource ID="getGrade" runat="server" ConnectionString="<%$ ConnectionStrings:CasesTimeConnection %>"
    SelectCommand="SELECT [gradeID], [gradeText] FROM [us开发者_C百科er_grades] WHERE ([visibleState] = @visibleState)">
    <SelectParameters>
        <asp:Parameter DefaultValue="True" Name="visibleState" Type="Boolean" />
    </SelectParameters>
</asp:SqlDataSource>

In page;

<EditItemTemplate>
<asp:DropDownList ID="GradeDropDownList" runat="server" DataSourceID="getGrade" DataTextField="gradeText" DataValueField="gradeID" OnDataBinding="GradeDropDownList_DataBinding" OnSelectedIndexChanged="GradeDropDownList_SelectedIndexChanged">
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="gradeLabel" runat="server" Text='<%# Bind("gradeText") %>'></asp:Label>
</ItemTemplate>


Retrieve LastModifiedDate while retrieving the records and while trying to update the record check the existing lastModifiedDate value with the one you retrieved. If they are different then throw an alert message / display new quantity.

Thanks

Shashi

0

精彩评论

暂无评论...
验证码 换一张
取 消