I'm trying to present results on an aspx web page where a store procedure parameter is defined by a dropdown list control on the page.
To help accomplish this, I have followed this guide from Microsoft and have my resultset presented in a DataGrid view. But I cannot seem to adapt it to present the resultset in a chart.

As you can see from my VB code below, I thought it would simply be a case of adapting the GridView databind to a Chart. I have tried various other options, and have successfully generated my data in a chart using a hard-coded parameter in an SQL statement on the ASP page. But when it comes to using the control, I get an empty chart.

Below is what I have so far. Any help greatly appreciated.

Imports System.Data.SqlClient

Public Class Report
    Inherits System.Web.UI.Page

    Protected MIUDropDownList As System.Web.UI.WebControls.DropDownList
    Protected ResultChart As DataVisualization.Charting.Chart
    Dim objConn As SqlConnection
    Dim objCmd As SqlCommand
    Dim dataReader As SqlDataReader
    Dim strSql As String

    Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not IsPostBack Then
            Dim objConn As SqlConnection
            Dim dataReader As SqlDataReader

            objConn = New SqlConnection("ConnectionString")
            strSql = "EXEC usp_GetRadioUnitSerialNumber"
            objCmd = New SqlCommand(strSql, objConn)
                dataReader = objCmd.ExecuteReader
                With MIUDropDownList
                    .DataSource = dataReader
                    .DataTextField = "RadioUnitSerialNumber"
                    .DataValueField = "RadioUnitSerialNumber"
                End With
            Catch ex As Exception

            End Try

        End If

    End Sub

    Protected Sub ButtonGetRadioUnit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ButtonGetRadioUnit.Click

        objConn = New SqlConnection("ConnectionString")

        strSql = "usp_RadioUnitReadingHistory '" & MIUDropDownList.SelectedItem.Value & "'"

        objCmd = New SqlCommand(strSql, objConn)

            dataReader = objCmd.ExecuteReader()
            'Bind to Grid
            GridView1.DataSource = dataReader
            ''Bind to Chart
            'ResultChart.DataSource = dataReader

        Catch ex As Exception
        End Try

    End Sub
End Class

ASPX page

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <asp:DropDownList ID="MIUDropDownList" runat="server" DataTextField="RadioUnitSerialNumber">
 <asp:Button ID="ButtonGetRadioUnit" runat="server" Font-Size="8pt" Height="20px" Text="Select MIU" Width="60px" OnClick="ButtonGetRadioUnit_Click" />
    <br />
     <asp:Chart ID="ResultChart" runat="server" Height="500px" Width="800px" >
            <asp:Series ChartType="Line" Name="Series1" XValueMember="DateTimeStamp" YValueMembers="Value">
            <asp:ChartArea Name="ChartArea1">

     <asp:GridView ID="GridView1" runat="server">


When you use the dropdown, do you get results in your GridView?

Yes. The GridView is altered as per the DropDown selection. That's working OK

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.