2

I have a control that holds a dropdownlist that holds variables (A, B, C, N/A). The variables are pulled from a class. When an item is submitted, in the database it will store the letter and an identifier. If the database entry with the identifier exists, this code runs fine, if the database does not hold an identifier for the entry (it does not exist yet) then I get an error.

Code:

 <EditItemTemplate>
                            <asp:DropDownList runat="server" 
                                ID="ddlQualityTypes" 
                                DataSource='<%# CodeLists.QualityTypes() %>'
                                DataTextField="strCode" 
                                DataValueField="strCode" 
                                SelectedValue='<%#Eval("strQualityCode")
    == null ? "A" : Eval("strQualityCode") %>'
                                />
                        </EditItemTemplate>

Any ideas on how to get around this?

EDIT: strQualityCode is the name of the variable that is databound to the object holding which letter corresponds to the item.

1
  • What should happen when the database does not hold an identifier for the entry? Commented Sep 8, 2011 at 19:56

1 Answer 1

1

I would make the field nullable in the database, and make it an optional parameter in your stored procedure. If the value of the dropdown is null or empty, don't pass the parameter to the stored procedure.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.