2013-10-23 16 views
1

我有包含ImageButton的網格。我想設置從aspx頁面,類似工具提示:使用硬編碼的字符串與來自ImageButton中的數據集的值連接工具提示

The user's id is <user_id> and his name is <user_name> 

其中user_iduser_name在網格的數據集字段。這是我的代碼:

<asp:TemplateField HeaderText=""> 
    <HeaderStyle HorizontalAlign="Left" /> 
    <ItemStyle HorizontalAlign="Left" /> 
    <ItemTemplate> 
     <asp:ImageButton ID="btnViewUser" runat="server" ToolTip=' <%# Eval("user_id") %>' 
                 AlternateText="View or edit the record" ImageUrl="~/images/Icon/view_text.png" 
                 CommandName="ViewOrder" CommandArgument='<%# Container.DisplayIndex %>' /> 
    </ItemTemplate> 
</asp:TemplateField> 

謝謝。

回答

0

最簡單,使用代碼隱藏,RowDataBound是最好的地方最易維護:

protected void Gridview1_RowDataBound(Object sender, GridViewRowEventArgs e) 
{ 
    if (e.Row.RowType == DataControlRowType.DataRow) 
    { 
     ImageButton btnViewUser = (ImageButton) e.Row.FindControl("btnViewUser"); 
     DataRow row = ((DataRowView) e.Row.DataItem).Row; 
     btnViewUser.Tooltip = string.Format("The user's id is {0} and his name is {1}" 
      , row.Field<int>("user_id") 
      , row.Field<string>("user_name")); 
    } 
} 

這裏是ASPX的方法(不知道這工作,我絕不會使用這樣的代碼):

<asp:ImageButton id="btnViewUser" runat="server" 
      Tooltip='<%# "The users id is "+ DataBinder.Eval(Container.DataItem, "user_id") +" and his name is "+ DataBinder.Eval(Container.DataItem, "user_name") +"" %>' 
      AlternateText="View or edit the record" 
      ImageUrl="~/images/Icon/view_text.png" 
      CommandName="ViewOrder" 
      CommandArgument='<%# Container.DisplayIndex %>' /> 
+0

但我想在aspx文件中實現這一點,如上所述 –

+0

類似於Tooltip ='<%#Eval(「user_id」)%>'但與我的硬編碼字符串連接,並與其他值 –

+0

我已更新問題和附加源代碼 –

相關問題