ASP.net DropDownList Wildcard trouble?

Capodecina
Permabanned
Joined
31 Dec 2003
Posts
5,172
Location
Barrow-In-Furness
Having some trouble getting a wildcard to work on a DropDownList.

When I try to load the page i'm getting the error:

"Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.FormatException: Input string was not in a correct format.

Source Error:"

Here's the SQL Query

Code:
SELECT Approved, Comments, Date, Hours, ID, TimeCode, Username FROM tblHours WHERE (Approved IS NULL) AND TimeCode LIKE @SelectedCodeID

And here's the relevant page code

Code:
 <asp:DropDownList ID="ActiveCodesDropDownList" runat="server" AppendDataBoundItems="True"
        AutoPostBack="True" DataSourceID="ObjectDataSource1" DataTextField="CodeName" DataValueField="CodeID"
        Width="300px">
        <asp:ListItem Value="*">-All-</asp:ListItem>
    </asp:DropDownList>

Tried it a couple of ways but no joy, I think it's because the DataValueField is an Integer?
 
Personally I'd do it slightly different. What is the data type for the TimeCode field? And what are the other potential values? 1, 2, 3 etc
 
DateType for the TimeCode field is an Integer. I'm displaying the name of the time code in the drop down for usability, but the actual value is the integer.
 
ok so I'd change the value filed fo the All list item to be 0 then change the sql to be

Code:
SELECT Approved, Comments, Date, Hours, ID, TimeCode, Username FROM tblHours WHERE (Approved IS NULL) AND (TimeCode = @SelectedCodeID OR @SelectedCodeID = 0)

That way if All aka 0 is selected the or portion of the SQL query is matched and all records are returned.
 
Back
Top Bottom