Pop up chart from GridView to display data based on row reference

此生再无相见时 提交于 2020-01-03 04:57:07

问题


I have created a gridview where a pop up chart appears when hovering over an image in the row.

It works amaisingly well and I have posted the solution in stackoverflow already (Popup chart in vb.net on mouse over)

My problem now is that I want the chart to be filtered by the 'Group' column, but I can't figure out how to transfer the 'name' value to the SqlDataSource1 query.

Here is the Gridview sample code:

    <asp:BoundField DataField="name" HeaderText="Group" SortExpression="name" />
    <asp:BoundField DataField="ASL" HeaderText="SL" ReadOnly="True" />
    <asp:TemplateField>
        <ItemTemplate>
            <div class="HoverDesc">
                <asp:Image ID="Image5" runat="server" Height="20px" src="Images/Icons/iGreen.png" />
                <p>
                    <asp:Chart ID="Chart2" runat="server" DataSourceID="SqlDataSource1" Height="141px">
                        <Series>
                            <asp:Series ChartType="Line" Name="Series1" XValueMember="date" YValueMembers="Value">
                            </asp:Series>
                        </Series>
                        <ChartAreas>
                            <asp:ChartArea Name="ChartArea1"></asp:ChartArea>
                        </ChartAreas>
                    </asp:Chart>
                </p>
            </div>
        </ItemTemplate>
    </asp:TemplateField>

Any ideas will be much appreciated.

Thanks


回答1:


I managed to theresolve it. I've got the inspiration from the following site: http://social.msdn.microsoft.com/Forums/vstudio/en-US/bb0548cc-90f7-4622-8ced-61ded9a63b3d/chart-in-gridview?forum=MSWinWebChart

If it helps someone, here is what I did:

In ASP I added a OnRowDataBound in the DataGrid and a SqlDataSource inside the ItemTemplate

OnRowDataBound="GridViewChart_RowDataBound"

In the vb (if you need C you will find it in the link above) code I've added the following

Protected Sub GridViewChart_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
    If e.Row.RowType = DataControlRowType.DataRow Then

        Dim RG_name As String = Replace(e.Row.Cells(0).Text, "amp;", "")
        Dim SQL As SqlDataSource = DirectCast(e.Row.FindControl("SqlDataSource10"), SqlDataSource)
        SQL.SelectParameters("name").DefaultValue = RG_name

    End If
End Sub


来源:https://stackoverflow.com/questions/19277384/pop-up-chart-from-gridview-to-display-data-based-on-row-reference

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!