【问题标题】:Tool Tip to show entire GridView row显示整个 GridView 行的工具提示
【发布时间】:2018-09-26 15:09:24
【问题描述】:

我想创建一个工具提示功能,该功能将显示网格视图中显示的所有用户数据。

预期结果:GridView 显示 Last_Name、First_Name、Telephone、Cell_Phone。我希望将鼠标悬停在该用户信息行上显示工具提示,并显示该工具提示中的所有数据。数据仅在用户使用我的搜索框功能时生成,因此它不能是静态工具提示字符串。我正在使用 sqldatasource 填写我不知道如何调用的 gridview。我唯一能找到的就是将 gridview 设置为我不想做的标签。任何指导将不胜感激。

<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSource1" GridLines="None" HorizontalAlign="Center" AllowPaging="True" AllowSorting="True" ForeColor="#333333">
    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    <Columns>
        <asp:BoundField DataField="Last_Name" HeaderText="Last_Name" SortExpression="Last_Name" />
        <asp:BoundField DataField="First_Name" HeaderText="First_Name" SortExpression="First_Name" />
        <asp:BoundField DataField="Middle_Int" HeaderText="Middle_Int" SortExpression="Middle_Int" />
        <asp:BoundField DataField="Telephone" HeaderText="Work Telephone" SortExpression="Telephone" />
        <asp:BoundField DataField="Cell_Phone" HeaderText="Work Cell" SortExpression="Cell_Phone" />
    </Columns>
</asp:GridView>

SQLDataSource 连接:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:myconnection %>" SelectCommand="SELECT [Last_Name], [First_Name], [Middle_Int], [Rank], [Telephone], [Cell_Phone], [Unit], [UserName]  FROM [Person_Search] WHERE (([Middle_Int] LIKE '%' + @Middle_Int + '%') OR ([Cell_Phone] LIKE '%' + @Cell_Phone + '%')  OR ([First_Name] LIKE '%' + @First_Name + '%')  OR ([Telephone] LIKE '%' + @Telephone + '%') OR ([Unit] = @Unit) OR ([Last_Name] LIKE '%' + @Last_Name + '%') OR ([UserName] LIKE '%' + @UserName + '%'))">
    <SelectParameters>
        <asp:ControlParameter ControlID="TextBox1" Name="Middle_Int" PropertyName="Text" />
        <asp:ControlParameter ControlID="TextBox1" Name="Cell_Phone" PropertyName="Text" Type="String" />
        <asp:ControlParameter ControlID="TextBox1" Name="First_Name" PropertyName="Text" Type="String" />
        <asp:ControlParameter ControlID="TextBox1" Name="Telephone" PropertyName="Text" Type="String" />
        <asp:ControlParameter ControlID="TextBox1" Name="Last_Name" PropertyName="Text" Type="String" />
    </SelectParameters>
</asp:SqlDataSource>

标签控件查看代码:

<asp:TemplateField HeaderText="Logid">
<ItemTemplate>
     <asp:Label ID="Label1" runat="server" Text='<%# Bind("cityid") %>' ToolTip='<%# Bind("cityName") %>' ></asp:Label>
 </ItemTemplate>

【问题讨论】:

    标签: c# asp.net tooltip


    【解决方案1】:

    您可以使用 RowDataBound 事件将 ToolTip 属性添加到 GridViewRow。

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        //check if the row is d datarow
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //cast the row back to a datarowview
            DataRowView row = e.Row.DataItem as DataRowView;
    
            StringBuilder tooltip = new StringBuilder();
    
            //add the data to the tooltip stringbuilder
            tooltip.Append(row["Last_Name"] + ", ");
            tooltip.Append(row["First_Name"] + ", ");
            tooltip.Append(row["Middle_Int"] + ", ");
            tooltip.Append(row["Telephone"] + ", ");
            tooltip.Append(row["Cell_Phone"]);
    
            //add the tooltip attribute to the row
            e.Row.Attributes.Add("ToolTip", tooltip.ToString());
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2012-10-20
      • 2018-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多