Hi,
I'm new to ASP.NET. I have a simple page with two controls (datagrid and dropdown box). The dropdown has a 4 digit year while the grid displays data depending on the year.
When the dropdown selection changes, I need the selected year to fire.
Here is the code I have but on the first selected value in the dropdown box fires:
Dim sqlConn As New SqlConnection("Data Source=dev2;uid=111;pwd=111;database=cunet_db") 'OleDbConnection
'open the connection
sqlConn.Open()
Dim YearComm As New SqlCommand("SELECT distinct(Year) FROM Holiday_tbl order by Year Desc", sqlConn)
'Populate the dropdown box with all sorted years
Dim YR As SqlDataReader = YearComm.ExecuteReader()
While YR.Read()
YearList.Items.Add(YR("Year"))
End While
YR.Close()
'create the command object to bring back all the valid holidays for selected year
Dim sqlComm As New SqlCommand("SELECT Value as Date,Type as Description FROM Holiday_tbl where year=" & YearList.SelectedValue & " order BY year,Month,Day", sqlConn)
Dim r As SqlDataReader = sqlComm.ExecuteReader(CommandBehavior.CloseConnection)
myDataGrid.DataSource = r
myDataGrid.DataBind()
r.Close()
I'm new to ASP.NET. I have a simple page with two controls (datagrid and dropdown box). The dropdown has a 4 digit year while the grid displays data depending on the year.
When the dropdown selection changes, I need the selected year to fire.
Here is the code I have but on the first selected value in the dropdown box fires:
Dim sqlConn As New SqlConnection("Data Source=dev2;uid=111;pwd=111;database=cunet_db") 'OleDbConnection
'open the connection
sqlConn.Open()
Dim YearComm As New SqlCommand("SELECT distinct(Year) FROM Holiday_tbl order by Year Desc", sqlConn)
'Populate the dropdown box with all sorted years
Dim YR As SqlDataReader = YearComm.ExecuteReader()
While YR.Read()
YearList.Items.Add(YR("Year"))
End While
YR.Close()
'create the command object to bring back all the valid holidays for selected year
Dim sqlComm As New SqlCommand("SELECT Value as Date,Type as Description FROM Holiday_tbl where year=" & YearList.SelectedValue & " order BY year,Month,Day", sqlConn)
Dim r As SqlDataReader = sqlComm.ExecuteReader(CommandBehavior.CloseConnection)
myDataGrid.DataSource = r
myDataGrid.DataBind()
r.Close()