Подсказка, чтобы показать всю строку GridView - PullRequest
0 голосов
/ 26 сентября 2018

Я хочу создать функцию всплывающей подсказки, которая будет отображать все пользовательские данные, отображаемые в виде сетки.

Ожидаемый результат: 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>

1 Ответ

0 голосов
/ 26 сентября 2018

Вы можете использовать событие 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());
    }
}
...