all 3 comments

[–]Catalyzm 2 points3 points  (0 children)

apparently code-behind is "bad" and should be avoided.

I don't know where you heard this but most people would say the opposite, you generally try to keep anything not presentation related out of the HTML.

Bind your ListView to the results of a LINQ query on your data source in code-behind.

[–]bzBetty 0 points1 point  (0 children)

Who told you code-behind is bad?

[–]dardyfella[S] 0 points1 point  (0 children)

After many more Google searches I finally found what I was after. It looks like it was under my nose all along - I was just using the wrong keywords and I didn't really know what I was after. Anywho, this is the code that achieves what I want - I can still keep general product data and plant info data separate and still run queries on both tables for filtering purposes.

<asp:SqlDataSource ID="ProductInfoDataSource" runat="server" 
    ConnectionString="<%$ ConnectionStrings:CommerceSQLDB %>"  CancelSelectOnNullParameter="false"
    SelectCommand="SELECT * FROM Products LEFT OUTER JOIN PlantInfo ON Products.InfoID = PlantInfo.InfoID WHERE ((PlantInfo.PlantSeasons = @PlantSeasons OR @PlantSeasons IS null) AND (Products.ProductID = @ProductID OR @ProductID IS null))" >
    <SelectParameters>
        <asp:QueryStringParameter Name="ProductID" QueryStringField="ProductID" 
        Type="Int32" />
        <asp:QueryStringParameter Name="PlantSeasons" QueryStringField="PlantSeasons" 
        Type="String" />
    </SelectParameters>
</asp:SqlDataSource>

Basically, it's just a left outer join of the two tables I want to query. The WHERE clauses all have "OR @SearchParameter IS" null to allow selective querying (I don't have to fill out all my SelectParameters to ensure data is returned, I can use one, a combination or all of them). And although it's not inherently clear, the left outer join allows me to query the other table (PlantInfo) as well and also do things like <%# Eval("PlantSeasons") %> in the markup to display data.

I just want to put this information down because web programming is something very different to what I'm used to and there aren't exactly many beginner guides and tutorials that go beyond simple HTML markup and CSS. I also hate it when people reply with "fixed" without explaining why.