locked
how to use DataBinder.Eval to get the data RRS feed

  • Question

  • User-86041214 posted

    Hi:

    I have a problem to get the dataitem in listviw, the following is the code snippet

                            <ItemTemplate>
                                <ul id="itemContainer" runat="server">
                                    <li>
                                        <asp:Button ID="btnDisplay" runat="server" Text='<%# Eval(??) %>'></asp:Button><br />
                                    </li>
                                </ul>
                            </ItemTemplate>
    

    the main problem is if the data source of listview is List<string>, since it will not have any columns name, how to 

    assign value to the text of button. Thanks.

    Tuesday, March 3, 2015 11:25 PM

Answers

  • User2103319870 posted

    abramhum.c.l

    the main problem is if the data source of listview is List<string>, since it will not have any columns name, how to 

    assign value to the text of button. Thanks.

    You can use '<%# Container.DataItem %>' instead of eval

    <ItemTemplate>
                                <ul id="itemContainer" runat="server">
                                    <li>
                                        <asp:Button ID="btnDisplay" runat="server" Text='<%# Container.DataItem %>'></asp:Button><br />
                                    </li>
                                </ul>
                            </ItemTemplate>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 3, 2015 11:34 PM

All replies

  • User2103319870 posted

    abramhum.c.l

    the main problem is if the data source of listview is List<string>, since it will not have any columns name, how to 

    assign value to the text of button. Thanks.

    You can use '<%# Container.DataItem %>' instead of eval

    <ItemTemplate>
                                <ul id="itemContainer" runat="server">
                                    <li>
                                        <asp:Button ID="btnDisplay" runat="server" Text='<%# Container.DataItem %>'></asp:Button><br />
                                    </li>
                                </ul>
                            </ItemTemplate>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 3, 2015 11:34 PM
  • User-86041214 posted

    It works. Thanks a lot

    Wednesday, March 4, 2015 3:49 AM