簡體   English   中英

如何將字符串與.aspx文件中的Bind()中的變量組合為DataList?

[英]How do I combine a string with a variable in Bind() in an .aspx file for a DataList?

我已經搜索過了,但是也許我使用了錯誤的關鍵字。

我有一個包含ImageButton的DataList,我想通過將其與Codebehind文件屬性和數據庫值返回的字符串組合來設置其ImageUrl屬性。

我的代碼strPath有一個稱為strPath的受保護屬性。

我想將其與aspx文件中的數據庫值結合在一起。 像這樣:

... ImgUrl = '<%#strPath+ Bind("senderPic")%>' ...

但這是行不通的。 我怎樣才能做到這一點?

編輯:

這是要求的DataList的完整代碼。 (問題出在ibtnUser元素中。

<asp:DataList ID="dtlstScraps" runat="server" CellSpacing="4" 
    onitemcommand="dtlstScraps_ItemCommand" 
    onitemdatabound="dtlstScraps_ItemDataBound">
    <ItemTemplate>
        <table class="style26">
            <tr>
                <td>
                    <asp:Panel ID="pnlHeader" runat="server" BackImageUrl="~/Images/scraphead.gif" 
                        Height="50px" Width="640px">
                        <table class="style27">
                            <tr>
                                <td class="style28">
                                    &nbsp;</td>
                                <td class="style29">
                                    **<asp:ImageButton ID="ibtnUser" ImageUrl='<%# strPath + DataBinder.Eval(Container.DataItem, "senderPic") %>' CommandName ="ImageClick" runat="server" Height="35px" Width="35px" />**
                                </td>
                                <td class="style34">
                                    <asp:LinkButton ID="lbtnUser" Text='<%#Bind("senderName")%>' CommandName="LinkClick" runat="server">User Page</asp:LinkButton>
                                </td>
                                <td class="style35">
                                    <asp:Label ID="lblTimeStamp" Text='<%#Bind("timestamp")%>' runat="server" ></asp:Label>
                                </td>
                                <td class="style33">
                                    &nbsp;</td>
                            </tr>
                        </table>
                    </asp:Panel>
                    <asp:Panel ID="Panel2" runat="server" Height="60px">
                        <asp:Label ID="lblMsg" runat="server" BackColor="#C9C9C9" BorderColor="#020246" 
                            BorderStyle="Solid" Height="50px" Text='<%# Bind("message") %>' Width="631px"></asp:Label>
                    </asp:Panel>
                </td>
            </tr>
        </table>
    </ItemTemplate>

</asp:DataList>

嘗試使用

ImageUrl='<%# ThePath + DataBinder.Eval(Container.DataItem, "picName") %>'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM