Hello@All
I am using ASP.NET Web matrix I linking to an SQL database. On my page I have a Mxdatagrid and a dropdwonlist. Once the Item in the drop dwon box is selected I want the mxdatagrid to filter the records by the selected item from the drop down box.
1. The SQLDataSourceControl is SELECT * FROM [tblUnitLog] this controls the MxDatagrid
2.
'************************
'Drop Dwon Select
'************************
Function QueryOfficerTitles() As System.Data.DataSet
Dim connectionString As String = "server='(local)'; trusted_connection=true; database='AIMSxpSQL'"
Dim dbConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(connectionString)
Dim queryString As String = "SELECT [tblParamsTitles].[Title] FROM [tblParamsTitles]"
Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.SqlClient.SqlDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New System.Data.DataSet
dataAdapter.Fill(dataSet)
Return dataSet
End Function
********************
Bind Drop Down to Page
********************
Sub Page_Load(Sender As Object, E As EventArgs)
If Not Page.IsPostBack Then
DropDownList1.DataTextField = "Title"
DropDownList1.DataSource = QueryOfficerTitles()
DropDownList1.DataBind()
End If
'********************************
'Get Officers this code asks for the Parameter Value for the Select command in this case it is IMTOfficer
'********************************
Function GetOfficers(ByVal iMTOfficer As String) As System.Data.DataSet
Dim connectionString As String = "server='(local)'; trusted_connection=true; database='AIMSxpSQL'"
Dim dbConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(connectionString)
Dim queryString As String = "SELECT [tblunitlog].[IncidentName], [tblunitlog].[IMTOfficer], [tblunitlog].[IMTN"& _
"ame], [tblunitlog].[DateIn], [tblunitlog].[TimeIn], [tblunitlog].[TimeOut] FROM "& _
"[tblunitlog] WHERE ([tblunitlog].[IMTOfficer] = @IMTOfficer)"
Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
Dim dbParam_iMTOfficer As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
dbParam_iMTOfficer.ParameterName = "@IMTOfficer"
dbParam_iMTOfficer.Value = iMTOfficer
dbParam_iMTOfficer.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_iMTOfficer)
Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.SqlClient.SqlDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New System.Data.DataSet
dataAdapter.Fill(dataSet)
Return dataSet
End Function
'*******************
'DropDownList Bind to Mxdatagrid Using above select statement
'******************
'Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs)
' MxDataGrid1.DataSource = GetOfficers(DropDownList1.Items(DropDownList1.SelectedIndex).Text)
'MxDataGrid1.DataBind()
'End Sub
Please Help Regards Silvertri
I am using ASP.NET Web matrix I linking to an SQL database. On my page I have a Mxdatagrid and a dropdwonlist. Once the Item in the drop dwon box is selected I want the mxdatagrid to filter the records by the selected item from the drop down box.
1. The SQLDataSourceControl is SELECT * FROM [tblUnitLog] this controls the MxDatagrid
2.
'************************
'Drop Dwon Select
'************************
Function QueryOfficerTitles() As System.Data.DataSet
Dim connectionString As String = "server='(local)'; trusted_connection=true; database='AIMSxpSQL'"
Dim dbConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(connectionString)
Dim queryString As String = "SELECT [tblParamsTitles].[Title] FROM [tblParamsTitles]"
Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.SqlClient.SqlDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New System.Data.DataSet
dataAdapter.Fill(dataSet)
Return dataSet
End Function
********************
Bind Drop Down to Page
********************
Sub Page_Load(Sender As Object, E As EventArgs)
If Not Page.IsPostBack Then
DropDownList1.DataTextField = "Title"
DropDownList1.DataSource = QueryOfficerTitles()
DropDownList1.DataBind()
End If
'********************************
'Get Officers this code asks for the Parameter Value for the Select command in this case it is IMTOfficer
'********************************
Function GetOfficers(ByVal iMTOfficer As String) As System.Data.DataSet
Dim connectionString As String = "server='(local)'; trusted_connection=true; database='AIMSxpSQL'"
Dim dbConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(connectionString)
Dim queryString As String = "SELECT [tblunitlog].[IncidentName], [tblunitlog].[IMTOfficer], [tblunitlog].[IMTN"& _
"ame], [tblunitlog].[DateIn], [tblunitlog].[TimeIn], [tblunitlog].[TimeOut] FROM "& _
"[tblunitlog] WHERE ([tblunitlog].[IMTOfficer] = @IMTOfficer)"
Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
Dim dbParam_iMTOfficer As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
dbParam_iMTOfficer.ParameterName = "@IMTOfficer"
dbParam_iMTOfficer.Value = iMTOfficer
dbParam_iMTOfficer.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_iMTOfficer)
Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.SqlClient.SqlDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New System.Data.DataSet
dataAdapter.Fill(dataSet)
Return dataSet
End Function
'*******************
'DropDownList Bind to Mxdatagrid Using above select statement
'******************
'Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs)
' MxDataGrid1.DataSource = GetOfficers(DropDownList1.Items(DropDownList1.SelectedIndex).Text)
'MxDataGrid1.DataBind()
'End Sub
Please Help Regards Silvertri