locked
In line condition RRS feed

  • Question

  • User-1212847090 posted
    Hello guys,

    So I want to be able to use a yes/no field to trigger a condition and display an image in a record set.

    Say the field name is chk_collect, when this value is true, I want to display an x for each record its true.

    Using asp classic, I'd write <td><% if Rs("chk_collect").value = true then %> x <%else%> <%end if%> </td>

    How would I do this in dot net, I know how to do it for any other control but not while it's in a record set

    Thanks in advance

    Ben
    Sunday, October 25, 2015 12:33 AM

Answers

  • User-1716253493 posted

    Inline condidtion sample in VB

    Text = '<%# IIF(Eval("fieldname"), "a", "b") %>'

    to set image visibility based yes/no column

    <asp:Image ID="Image1" runat="server" Visible='<%# Eval("yesnocolumn") %>' />

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, October 25, 2015 9:32 PM

All replies

  • User325035487 posted
    <td> @(chk_collect ? "x":"y") </td>

    Assuming you declare the variable as

    bool chk_collect = false;
    //Then from you data base update the value..
    chk_collect = queryddata.chk_collect;

    You can also do this for other data types..

    <td> @(integervalue == 123 ? 500:1000) </td>
    Sunday, October 25, 2015 1:22 AM
  • User-1212847090 posted

    I would declare the variable in the code behind on load event, would this be a correct assumption?

    Thanks


    Ben

    Sunday, October 25, 2015 1:36 AM
  • User-1212847090 posted

    How would I work it into this?

    <asp:Label ID="lblChkCollect" runat="server" Text='<%# Bind("chk_collectfrombranch") %>' />

    Thanks in Advance

    Ben

    Sunday, October 25, 2015 1:56 AM
  • User325035487 posted

    There is no runat server option in Web Pages (razor)

    you cant run that code in Web Pages

    <label for="inputfieldid">@(chk_collectfrombranch == true ? "Yes":"No")</label>

    Sunday, October 25, 2015 2:04 AM
  • User-1212847090 posted

    Thank you buddy

    Sunday, October 25, 2015 2:11 AM
  • User-1212847090 posted

    I shouldn't use runat "server" in razor text?  If I take that out, I get a parser error??

    It's actually all over them hey, thanks for the heads up

    <asp:TemplateField ShowHeader="False">
    <HeaderTemplate>
    <asp:LinkButton ID="lbtnFilter" runat="server" CausesValidation="false" CommandName="" Text="กรอง" OnClick="lbtnFilter_Click" /><br />
    <asp:LinkButton ID="lbtnReset" runat="server" CausesValidation="false" CommandName="" Text="รีเซท" OnClick="lbtnReset_Click" />
    </HeaderTemplate>
    <HeaderStyle Width="10%" />
    <ItemTemplate>
    <%--OnClick="lbtnEdit_Click" --%>
    <%--<asp:LinkButton ID="lbtnEdit" runat="server" CausesValidation="false" CommandName="Edit" Text="ส่วนลด" />--%>

    <asp:LinkButton ID="lbtnDel" runat="server" CommandName="delete1" CommandArgument='<%# Bind("Ship_order_ID") %>' Text="ลบ" OnClientClick="return confirm('ยกเลิกบิลนี้');" Visible="false" CausesValidation="false" />

    <asp:LinkButton ID="lbtnCheck" runat="server" CommandName="check" CommandArgument='<%# Bind("Ship_order_ID") %>' OnClientClick="return confirm('Check?');" CausesValidation="false">Check</asp:LinkButton>

    <asp:LinkButton ID="lbtnCollect" runat="server" CommandName="collect" CommandArgument='<%# Bind("Ship_order_ID") %>' OnClientClick="return confirm('Collect?');" CausesValidation="false">Collect</asp:LinkButton>

    <asp:LinkButton ID="lbtnCredit" runat="server" CommandName="credit" CommandArgument='<%# Bind("Ship_order_ID") %>' OnClientClick="return confirm('Credit?');" CausesValidation="false">Credit</asp:LinkButton>

    <asp:LinkButton ID="lbPaid" runat="server" CommandName="paid" CommandArgument='<%# Bind("Ship_order_ID") %>' OnClientClick="return confirm('Paid?');" CausesValidation="false">Paid</asp:LinkButton>

    <a href='<%# Eval("ship_order_id", "bill.aspx?no={0}") %>' target="_blank">bill</a>

    <asp:Label ID="lblChkCollect" runat="server" Text='<%# Bind("chk_collectfrombranch") %>' />
    </ItemTemplate>
    <EditItemTemplate>
    <asp:LinkButton ID="lbtnUpdate" runat="server" CausesValidation="True" CommandName="Update" Text="อัพเดท" OnClientClick="return confirm('Do you want to update this row?');" />
    <asp:LinkButton ID="lbtnCancel" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
    </EditItemTemplate>
    </asp:TemplateField>

    So the runat="server", I may as remove anyway??

    Sunday, October 25, 2015 2:16 AM
  • User325035487 posted

    You are using different technology.

    This forum for razor syntax -See examples here  http://www.asp.net/web-pages/overview/exploring-webmatrix

    Sunday, October 25, 2015 6:17 AM
  • User-1716253493 posted

    Inline condidtion sample in VB

    Text = '<%# IIF(Eval("fieldname"), "a", "b") %>'

    to set image visibility based yes/no column

    <asp:Image ID="Image1" runat="server" Visible='<%# Eval("yesnocolumn") %>' />

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, October 25, 2015 9:32 PM
  • User-1212847090 posted

    Awesome, thanks once again, you're always coming to my rescue, I hope to learn from you!

    Tuesday, October 27, 2015 1:52 AM