locked
Filtering on the WebGrid on booleans - users don't understand RRS feed

  • Question

  • User379720387 posted

    I need to figure out a way to improve my code so that a layperson can use it.

    The issue is related to columns with datatype bit that I have in my webgrid. The webgrid shows either a true or false. This is slightly confusing for a regular user. I have improved this by using pictures of checkmarks and question marks.

    I also have implemented the filtering method as detailed by mikesdotnetting, currently there is a dropdown box with 0 and 1. Most users don't understand what that means.

    Below is the thread I created months ago that never got answered.

    I have chosen to set a flag IsDeleted to true whenever I want a record to appear deleted, rather than outright deleting it.

    Now I need to figure out a way to show or not show deleted records. What I have so far does not show deleted records regardless of the value of my dropdown with choices Yes or No. Here are the functional elements. IsDeleted has two entries Yes or No, its purpose is to fill the dropdown.

        var query3 = "SELECT DISTINCT IsDeletedId FROM IsDeleted ORDER BY IsDeletedId DESC";
        var showdeleted = db.Query(query3);

    and more

    var selectQueryString = @"SELECT OrganizerID, OAbbreviation, OName, OState, OLink FROM Organizers WHERE OAbbreviation LIKE @0 AND OName LIKE @1 AND OState LIKE @2 AND OIsDeleted LIKE @3"; var OAbbreviations = "%" + Request["OAbbreviations"] + "%"; var ONames = "%" + Request["ONames"] + "%"; var OStates = "%" + Request["OStates"] + "%"; var OIsDeleted = Request["OIsDeleted"]; var data = db.Query(selectQueryString, OAbbreviations, ONames, OStates, OIsDeleted);

    and the dropdown:

     Show Deleted: <select name="OIsDeleted"> <option></option> @foreach(var item3 in showdeleted){ <option @(Request["OIsDeleted"] == item3.IsDeletedId ? " selected=\"selected\"" : "")>@item3.IsDeletedId</option> } </select>

    EDIT:

    Made some progress. The general principle works provided the dropdown values are 1 and 0 as nvarchar.

    I would like the dropdown values to be Yes and No.

    Any suggestions on how to make that work?

    Anyone?

    Thursday, July 25, 2013 10:30 PM

Answers

  • User-821857111 posted

    Do I understand this correctly? Your IsDeleted table exists purely to provide data to populate a dropdown with Yes or No? If so, that is an unnecessary level of complexity in my opinion. I would just render the dropdown using basic HTML:

    <select name="OIsDeleted">
        <option value="false">No</option>
        <option value="true">Yes</option>
    </select>

    You can dynamically build the SQL based on the selection. Here's a simplified version for example purposes:

    var sql = "SELECT * From MyTable";
    if(!Request["OIsDeleted"].AsBool()){
        sql += " WHERE IsDeleted = 0";
    }
    var result = db.Query(sql); 


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 26, 2013 12:41 AM

All replies

  • User-821857111 posted

    Do I understand this correctly? Your IsDeleted table exists purely to provide data to populate a dropdown with Yes or No? If so, that is an unnecessary level of complexity in my opinion. I would just render the dropdown using basic HTML:

    <select name="OIsDeleted">
        <option value="false">No</option>
        <option value="true">Yes</option>
    </select>

    You can dynamically build the SQL based on the selection. Here's a simplified version for example purposes:

    var sql = "SELECT * From MyTable";
    if(!Request["OIsDeleted"].AsBool()){
        sql += " WHERE IsDeleted = 0";
    }
    var result = db.Query(sql); 


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 26, 2013 12:41 AM
  • User-1454326058 posted

    Hi wavemaster,

    Since we haven't heard from you for a long time, I temporarily close this case. I mark useful reply as answer. If you have any concerns, please free feel to reopen it or submit a new question. Thanks for your understanding.

    Thanks

    Best Regards

    Thursday, August 1, 2013 8:36 AM