Databinder.Eval passed as argument is choking

Ask a Question related to ASP.NET Data Grid Control, Design and Development.

  1. #1

    Default Databinder.Eval passed as argument is choking

    I have a datagrid that has a boolean column. The sql data is a bit stored
    as a 1 or 0. Doing a straight up DataBinder.Eval(Container.DataItem,
    "MyColumn") displays a "True" or "False" in the grid. No problems here.

    What I want is for it to display a "Yes" or "No". So I'm using a
    TemplateColumn instead of a BoundColumn so I can pass the value into a
    function and return a string that says Yes or No. My problem is that the
    function won't take the value seemingly no matter how I cast or don't cast
    the argument when I send or in the receiving mechanism of the function.

    In the aspx page:

    <asp:TemplateColumn HeaderText="Approved">
    <ItemTemplate>
    <%# FormatYesOrNo(DataBinder.Eval(Container.DataItem, "MyBitColumn")) %>
    </ItemTemplate>
    </asp:TemplateColumn>

    In the code behind:
    public string FormatYesOrNo(bool x)
    {
    string z = "Yes";
    if (x != true)
    z = "No";
    return z;
    }

    I tried casting the late bound info the aspx to a bool (e.g.
    (bool)DataBinder.Eval...), but that didn't work. I tried changing the
    FormatYesOrNo(bool x) in the code behind to FormatYesOrNo(string x) and
    changing the guts accordingly, but that didn't work.

    Any help appreciated.

    -TJ





    TJ Guest

  2. Similar Questions and Discussions

    1. Setting Visible with Databinder.Eval
      Hi, I hope this is the right forum for my question. I have a Repeater control in which I have two panels. Only one panel should be visible at a...
    2. Handling Nulls in Databinder.Eval
      I had a problem, now it's fixed, and now I have a concern on why isn't there a better way. The question is: How do you handle NULLs in your control...
    3. DataGrid - DataBinder.Eval
      I am using a Datagrid and am populating the column header which is being picked up from a database. My problem is that if the column name conatins...
    4. Complete syntax of DataBinder.Eval() ?
      I've been using DataBinder.Eval(container, expression, format) to late-bind controls in an aspx template with a typed dataset, but finding the...
    5. DataBinder.Eval Problem
      Hi Use <%#DataBinder.Eval(Container.DataItem, "cat1") %> HTH Prasad "Frosty" <programmerx2002x@aol.com> wrote in message
  3. #2

    Default Re: Databinder.Eval passed as argument is choking

    Try following:

    <asp:TemplateColumn HeaderText="Approved">
    <ItemTemplate>
    <%# (DataBinder.Eval(Container.DataItem, "MyBitColumn")) ? "Yes" : "No" %>
    </ItemTemplate>
    </asp:TemplateColumn>

    HTH

    "TJ" <teejay@newsgroups.nospam> wrote in message
    news:%23Mtyo7azFHA.3408@TK2MSFTNGP09.phx.gbl...
    >I have a datagrid that has a boolean column. The sql data is a bit stored
    >as a 1 or 0. Doing a straight up DataBinder.Eval(Container.DataItem,
    >"MyColumn") displays a "True" or "False" in the grid. No problems here.
    >
    > What I want is for it to display a "Yes" or "No". So I'm using a
    > TemplateColumn instead of a BoundColumn so I can pass the value into a
    > function and return a string that says Yes or No. My problem is that the
    > function won't take the value seemingly no matter how I cast or don't cast
    > the argument when I send or in the receiving mechanism of the function.
    >
    > In the aspx page:
    >
    > <asp:TemplateColumn HeaderText="Approved">
    > <ItemTemplate>
    > <%# FormatYesOrNo(DataBinder.Eval(Container.DataItem, "MyBitColumn")) %>
    > </ItemTemplate>
    > </asp:TemplateColumn>
    >
    > In the code behind:
    > public string FormatYesOrNo(bool x)
    > {
    > string z = "Yes";
    > if (x != true)
    > z = "No";
    > return z;
    > }
    >
    > I tried casting the late bound info the aspx to a bool (e.g.
    > (bool)DataBinder.Eval...), but that didn't work. I tried changing the
    > FormatYesOrNo(bool x) in the code behind to FormatYesOrNo(string x) and
    > changing the guts accordingly, but that didn't work.
    >
    > Any help appreciated.
    >
    > -TJ
    >
    >
    >
    >
    >

    Elton Wang Guest

  4. #3

    Default Re: Databinder.Eval passed as argument is choking

    I get this now:
    "CS0029: Cannot implicitly convert type 'object' to 'bool'"

    Seems closer. Thought it was a bool to begin with. I'm just reading a bit
    datatype column from a SQL Server 2K table.

    "Elton Wang" <elton_wang@hotmail.com> wrote in message
    news:%23gLpaQbzFHA.3892@TK2MSFTNGP12.phx.gbl...
    > Try following:
    >
    > <asp:TemplateColumn HeaderText="Approved">
    > <ItemTemplate>
    > <%# (DataBinder.Eval(Container.DataItem, "MyBitColumn")) ? "Yes" : "No" %>
    > </ItemTemplate>
    > </asp:TemplateColumn>
    >
    > HTH
    >
    > "TJ" <teejay@newsgroups.nospam> wrote in message
    > news:%23Mtyo7azFHA.3408@TK2MSFTNGP09.phx.gbl...
    >>I have a datagrid that has a boolean column. The sql data is a bit stored
    >>as a 1 or 0. Doing a straight up DataBinder.Eval(Container.DataItem,
    >>"MyColumn") displays a "True" or "False" in the grid. No problems here.
    >>
    >> What I want is for it to display a "Yes" or "No". So I'm using a
    >> TemplateColumn instead of a BoundColumn so I can pass the value into a
    >> function and return a string that says Yes or No. My problem is that the
    >> function won't take the value seemingly no matter how I cast or don't
    >> cast the argument when I send or in the receiving mechanism of the
    >> function.
    >>
    >> In the aspx page:
    >>
    >> <asp:TemplateColumn HeaderText="Approved">
    >> <ItemTemplate>
    >> <%# FormatYesOrNo(DataBinder.Eval(Container.DataItem, "MyBitColumn")) %>
    >> </ItemTemplate>
    >> </asp:TemplateColumn>
    >>
    >> In the code behind:
    >> public string FormatYesOrNo(bool x)
    >> {
    >> string z = "Yes";
    >> if (x != true)
    >> z = "No";
    >> return z;
    >> }
    >>
    >> I tried casting the late bound info the aspx to a bool (e.g.
    >> (bool)DataBinder.Eval...), but that didn't work. I tried changing the
    >> FormatYesOrNo(bool x) in the code behind to FormatYesOrNo(string x) and
    >> changing the guts accordingly, but that didn't work.
    >>
    >> Any help appreciated.
    >>
    >> -TJ
    >>
    >>
    >>
    >>
    >>
    >
    >

    TJ Guest

  5. #4

    Default Re: Databinder.Eval passed as argument is choking

    Nevermind...got it:

    ((bool)DataBinder.Eval(Container.DataItem, "AJGApproved")) ? "Yes" : "No"

    Just had to add the final casting touch. : )

    Thank you so much!



    "Elton Wang" <elton_wang@hotmail.com> wrote in message
    news:%23gLpaQbzFHA.3892@TK2MSFTNGP12.phx.gbl...
    > Try following:
    >
    > <asp:TemplateColumn HeaderText="Approved">
    > <ItemTemplate>
    > <%# (DataBinder.Eval(Container.DataItem, "MyBitColumn")) ? "Yes" : "No" %>
    > </ItemTemplate>
    > </asp:TemplateColumn>
    >
    > HTH
    >
    > "TJ" <teejay@newsgroups.nospam> wrote in message
    > news:%23Mtyo7azFHA.3408@TK2MSFTNGP09.phx.gbl...
    >>I have a datagrid that has a boolean column. The sql data is a bit stored
    >>as a 1 or 0. Doing a straight up DataBinder.Eval(Container.DataItem,
    >>"MyColumn") displays a "True" or "False" in the grid. No problems here.
    >>
    >> What I want is for it to display a "Yes" or "No". So I'm using a
    >> TemplateColumn instead of a BoundColumn so I can pass the value into a
    >> function and return a string that says Yes or No. My problem is that the
    >> function won't take the value seemingly no matter how I cast or don't
    >> cast the argument when I send or in the receiving mechanism of the
    >> function.
    >>
    >> In the aspx page:
    >>
    >> <asp:TemplateColumn HeaderText="Approved">
    >> <ItemTemplate>
    >> <%# FormatYesOrNo(DataBinder.Eval(Container.DataItem, "MyBitColumn")) %>
    >> </ItemTemplate>
    >> </asp:TemplateColumn>
    >>
    >> In the code behind:
    >> public string FormatYesOrNo(bool x)
    >> {
    >> string z = "Yes";
    >> if (x != true)
    >> z = "No";
    >> return z;
    >> }
    >>
    >> I tried casting the late bound info the aspx to a bool (e.g.
    >> (bool)DataBinder.Eval...), but that didn't work. I tried changing the
    >> FormatYesOrNo(bool x) in the code behind to FormatYesOrNo(string x) and
    >> changing the guts accordingly, but that didn't work.
    >>
    >> Any help appreciated.
    >>
    >> -TJ
    >>
    >>
    >>
    >>
    >>
    >
    >

    TJ Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139