Filter and ALL gridview contain integer with dropdownlist NO CODE? RRS feed

  • Question

  • User-1070822473 posted

    I read lot of nice posts about filtering of grid.
    One of that is realy nice , and I am happy on the writer, and quality.

    I know I am newbe at here, but in the real life i never see  like this

    This a first.

    When I try this codes with Updateparameters, I got a lot of problems. Even if i decrease the list to only ONE collumn.

    Second. I never see tables like this (only strings?) Most of bussiness application works mixed data rows included Float numbers, Integers, Dates....
    This methods will die on basic Integers.

    In a real life, most of bussiness system UI need the cascaded filters, vica-versa filters.
    Simple egs.:
    You have a products, with is have brand, and product category.
    Off course you plan the database as N model database.
    Based on that, at the end you will have 3 table (products, brands, product category)
    If you want to think for the future, you will extend to 4 table (Products, Brands, Category and Keytable for store relationship and create a lot of good, speed views, storaged procedures,,,etc)

    If you have a time, start to game with that, and at the end You will got a crasy on ASP.NET controls

    My best Stupid thing:
    when you bind the FIRST-Dropdownlist to "A" datasource after you add one item directly to the dropdownlist,
    and you filter "A" datasource with other one SECOND-Dropdownlist you will got a crasy, because if the autopostback is True on each Dropdownlist, the FIRST-dropdownlist will contain all of records plus the new filtered records.

    If i set the AppendDataBoundItems to False back to normal operation, but i loose the extra added item.

    Ok no problem, go to Code, and do in inline. Ok works, but, when you extend the code and UI with more DDL-s all off SQLdatacontrols come to HELL MIXER operation with hundred type of stupid things.

    My best: if you have a Gridview, and you change the Selectcommand from code on this Gridview datasource, looks ok, but when you do a edit on item, the gridview do the changings on other item.

    Unlogical. There are Stupid.

    Before You start laugh, YES the item in database  HAS ID as indexed individual KEY. Othervise you never get a the UPDATE and INSERT avaiability in SQLdataSource....

    I did game a lot with ASP.NET and stupid dropdownlist (realy, the ASP.NET dDL fully stupid)

    At the end I goes Back to classic ASP, and finish the hole project (hundreds of dropdownlist , grids, cascaded filters, AJAX views, twoway panels, XML-s etc...etc...) in four days.
    And of course, the number of program lines is less then one article sample program lines here in this forum.

    So somebody tell me, how we can accept this is the way of programming?

    You see the amount of the Code linked article on the top?

    Bless off programing on ONE FILTER DropDOWN on ONE TABLE on one way (just select).

    How be come if I wants more?

    If I wants to go to the club, I never start to build a street, city, country, and learn how the alcohol maded, and how the music is coing out from speakers, and how i hear it, and how my muscles do what i want as dance...
    Just take my friends, and go on a short way.

    Never mind, you got a help :) from 12 year of expernce of oldscool programming :)))

    If You want's FILTER on two collums witch is unfortunatly contain integers (filter and all, cascaded, vica versa with updates, inserts) there is a simple way, without ONE row of programming, just use TSQL goodies:

    Don't forget, the target is without ONE character CODING! Because your time is  too expensive to spend on stupid Dropdownlist....

    you have a two datasource
    one for First dropdownlist, one for second dropdownlist

    The base of trick is: you never have auto identify ID in SQL with zero....
    so if you do that: Where (ID = @reqestedID) OR (@requestedID = 0)
    you will got all off line if the @requestedID set to 0, and you will got a single value when the @requestedID is something else. Good to know for late.

    Ok, go next
    how i will add item to the STUPID dropdownlist, without the knowed cached items problem, without any programing?

    the answer is SQL UNION clause
    so add the UNION into the the two dropdownlist datasource, and after that you allways get a first row witch is "ALL" on the text and 0 on the data.
    But, whats happened if i go to ordered in dropdownlist and one item is start with number??
    Nothing, just put a simple space before ALL looks like ' ALL', nobody will see, because in the dropdownlist you have a empty area before textlabels.

    Nice trick, no stupid databind(); , Clear(), items.add(blalblablal.... VOID in out, sub bla blabla  on Stupid ASP.NET Dropdownlist

    Second. You have a two Dropdownlist, and you want to filter the second dropdownlist based on first, but if you select "All" on the second list you want to see the results based only on second dropdownlist

    no problem, use the datasource goodies.. <selectparameters> and push the first DDL value to second DDL datasource
    Hmmm i like Microsoft :)

    but how i got vica versa filtering? ? ? (All - chield) (ALL-ALL) (parent - ALL) (parent - chield)
    think again on SQL...
    combine two goodies into one :)
    put to end... Where ((ID = @reqestedID) OR (@requestedID = 0)) AND ((ID2 = @reqestedID2) OR (@requestedID2 = 0))

    Done, believe me will work...

    and here is the gridview where you want to see the results with correct updating,
    BUT for interested the update, insert, and select is coming fromdifferent tables, views....

    The FULL code sample (on ASPX page with simple tools):

    <asp:SqlDataSource ID="brands" runat="server"

    ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"

    SelectCommand="Select ' ALL' as [brand], 0 as [brand_id] union SELECT distinct [brand], [brand_id] FROM [filter_brand_category_relations_view]">


    <asp:SqlDataSource ID="categories" runat="server"

    ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"

    SelectCommand="Select ' All' as [category], 0 as [category_id] union SELECT distinct [category], [category_id] FROM [filter_brand_category_view] where ([category_id] = @categoryid) or( @categoryid = 0)" >


    <asp:ControlParameter ControlID="category_filter" Type="Int32" Name="categoryid" PropertyName="SelectedValue" />



    <asp:SqlDataSource ID="products" runat="server"

    ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"

    DeleteCommand="DELETE FROM [table1] WHERE [ID] = @ID"

    InsertCommand="INSERT INTO [table2] blablabla...."

    SelectCommand="SELECT [ID], [table3], blablabla... where ((brand_id =@brandid) OR (@brandid=0)) and((category_id = @categoryid) or (@categoryid = 0))"

    UpdateCommand="UPDATE blalblalbla... WHERE [ID] = @ID">


    <asp:ControlParameter ControlID="brand_filter" Type="Int32" Name="brandid" DefaultValue="0" PropertyName="SelectedValue" />

    <asp:ControlParameter ControlID="category_filter" Type="Int32" Name="categoryid" DefaultValue="0" PropertyName="SelectedValue" />



    <asp:Parameter Name="ID" Type="Int32" />









    <asp:DropDownList ID="brand_filter" runat="server" AutoPostBack="True"

    DataSourceID="brands" DataTextField="brand" DataValueField="brand_id" AppendDataBoundItems="false">



    <asp:DropDownList ID="category_filter" runat="server" DataSourceID="categories" DataTextField="category" DataValueField="category_id" AutoPostBack="true" >


    <br />

    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" PageSize="25"

    AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="ID"

    DataSourceID="PRODUCTS" Width="905px">




    Footer, save, publish, coffee, smile and take a care on the new administrator girl....

    See one row of programmings on C# or VB code page? Save your time for your life

    The answer is: NO


    Tuesday, August 9, 2011 10:43 PM

All replies