Hi @Joseph Hedbon ,
Based on your description, I think you can use OLEDB to read and write to Excel.
I wrote an example to bind all the data to the Gridview, then filter out the desired data based on the dropdown list, and put the Rate in the Lable.
You can modify the code according to your needs.
<asp:DropDownList ID="dropdown1" runat="server" OnSelectedIndexChanged="ddlAge_SelectedIndexChanged" AutoPostBack="true" AppendDataBoundItems="True">
<asp:ListItem Selected="True" Value="Choose">- Choose -</asp:ListItem>
</asp:DropDownList>
<asp:GridView ID="Grid1" runat="server">
</asp:GridView>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>|
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>|
<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>|
<asp:Label ID="lbl1" runat="server" />
Dim x As OleDbConnection
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
GenerateExcelData("Choose")
End If
End Sub
Protected Sub ddlAge_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
GenerateExcelData(dropdown1.SelectedValue)
End Sub
Private Sub GenerateExcelData(ByVal age As String)
Try
Dim read As String = Path.GetFullPath(Server.MapPath("~/Book2.xlsx"))
If Path.GetExtension(read) = ".xls" Then
x = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & read & ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=2""")
ElseIf Path.GetExtension(read) = ".xlsx" Then
x = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & read & ";Extended Properties='Excel 12.0;HDR=YES;IMEX=1;';")
End If
x.Open()
Dim y As OleDbCommand = New OleDbCommand()
Dim z As OleDbDataAdapter = New OleDbDataAdapter()
Dim dset As DataSet = New DataSet()
y.Connection = x
y.CommandType = CommandType.Text
y.CommandText = " SELECT distinct([Age]) FROM [Sheet1$]"
z = New OleDbDataAdapter(y)
z.Fill(dset, "Age")
dropdown1.DataSource = dset.Tables("Age").DefaultView
If Not IsPostBack Then
dropdown1.DataTextField = "Age"
dropdown1.DataValueField = "Age"
dropdown1.DataBind()
End If
If Not String.IsNullOrEmpty(age) AndAlso age <> "Choose" Then
y.CommandType = CommandType.Text
y.CommandText = " SELECT * FROM [Sheet1$] where Age= @Age"
y.Parameters.AddWithValue("@Age", age)
Using reader As OleDbDataReader = y.ExecuteReader()
While reader.Read()
Label1.Text = reader("Rate1").ToString()
Label2.Text = reader("Rate2").ToString()
Label3.Text = reader("Rate3").ToString()
End While
End Using
x.Close()
Else
y.CommandText = "SELECT * FROM [Sheet1$]"
End If
z = New OleDbDataAdapter(y)
z.Fill(dset)
Grid1.DataSource = dset.Tables(1).DefaultView
Grid1.DataBind()
Catch ex As Exception
lbl1.Text = ex.ToString()
Finally
x.Close()
End Try
End Sub

Best regards,
Lan Huang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.