簡體   English   中英

如何在頁面加載時更改數據列表中的標簽文本

[英]how to change text of label in datalist at page load

<asp:datalist ID="Datalist1" runat="server" 
                      Width="500px" >
                    <ItemTemplate>


<asp:Button ID="btnviewfullprofile" runat="server"   Text="View Full Profile" ToolTip="Click for Full Profile of User"  CommandArgument='<%#Eval("Uid")%>'  CommandName="fullprofile" />



 <asp:Button ID="sendinterest" runat="server" Text="Send Interest"  CommandArgument='<%#Eval("Uid")%>'  CommandName="sendinterest" />

 <asp:Label ID="lblstatus" runat="server" Visible="False"     ></asp:Label>                 


</ItemTemplate>
   </asp:datalist>

標簽文本將根據數據庫中存儲的狀態值而變化。

按鈕代碼

if (e.CommandName == "fullprofile")
    {
        int Id = int.Parse(e.CommandArgument.ToString());
        Response.Redirect("~/FullProfile.aspx?Id=" + Id);


 `enter code here`   }

但是我應該為標簽寫些什么,以便標簽文本應根據數據庫中存儲的狀態值自行更改

如果我理解正確,則需要將HTML更改為以下內容:

<asp:Label ID="lblstatus" runat="server" Visible="False" 
   Text='<%# Eval("DatabaseField") %>' />

您已經將其用於按鈕的CommandArgument 顯然,您需要用要顯示為文本的字段名稱替換“ DatabaseField”。 ASP.net將使用數據源中的正確值填充Text屬性。

當您從數據庫綁定按鈕的命令參數時,可以使用相同的方式綁定標簽的text屬性

<asp:Label ID="lblstatus" runat="server" Visible="False" Text= '<%#Eval("textfield")%>'    ></asp:Label>  

如果需要更多高級控制,則需要在綁定項目時進行設置,請參閱此處的詳細信息http://msdn.microsoft.com/zh-cn/library/system.web.ui.webcontrols.datalist.itemdatabound.aspx

暫無
暫無

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

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