Dim conn As SqlConnection = Nothing
Try
Dim connString As String = "Data Source=;Initial Catalog=;Integrated Security=True"
conn = New SqlConnection(ConfigurationManager.ConnectionStrings("ConString").ConnectionString)
Dim query As String = "SELECT * FROM userProfilesTbl
LEFT JOIN storeTbl ON userProfilesTbl.st_id = storeTbl.st_id
LEFT JOIN shiftTbl ON userProfilesTbl.wa_id = shiftTbl.wa_id
LEFT JOIN userAssessmentTbl ON userProfilesTbl.UserId = userAssessmentTbl.UserId
LEFT JOIN myTbl ON userAssessmentTbl.tt_id = myTbl.tt_id
LEFT JOIN setsTbl ON trainingTbl.s_id = setsTbl.s_id
WHERE userProfilesTbl.st_id=@st_id AND userProfilesTbl.wa_id=@wa_id AND DATEPART(m,t_date) = @m_date AND DATEPART(yyyy,t_date) = @y_date ORDER BY surname ASC"
'AND t_date=@t_date
Dim cmd As SqlCommand = New SqlCommand(query, conn)
conn.Open()
cmd.Parameters.AddWithValue("@st_id", myLblStore.Value().ToString)
cmd.Parameters.AddWithValue("@wa_id", myLblShift.Value().ToString)
cmd.Parameters.AddWithValue("@m_date", ddlMonth.SelectedValue().ToString())
cmd.Parameters.AddWithValue("@y_date", ddlYear.SelectedValue().ToString())
Dim dr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
Dim dt As DataTable = New DataTable()
Dim dt2 As DataTable = New DataTable()
dt.Load(dr)
dt2 = GetInversedDataTable(dt, "surname", "setName", "o_id", "", True)
GridView1.DataSource = dt2
GridView1.DataBind()
Catch ex As SqlException
' handle error
Catch ex As Exception
' handle error
Finally
conn.Close()
End Try
Where did you put the code that
chaaraan suggested ? It should be in the event handler of the drop downlist's you wanna use as filter or the button click event if you are using a button to trigger the filter oprtaion of the gridview.
chaaraan
Contributor
2170 Points
484 Posts
Re: Filter Datatable GridView with DropDownList
Nov 28, 2012 03:55 PM|LINK
Hi
Could you please try this code
Public Sub BindWatchGrid()
Dim conn As SqlConnection = Nothing
Try
Dim connString As String = "Data Source=;Initial Catalog=;Integrated Security=True"
conn = New SqlConnection(ConfigurationManager.ConnectionStrings("ConString").ConnectionString)
Dim query As String = "SELECT * FROM userProfilesTbl
LEFT JOIN storeTbl ON userProfilesTbl.st_id = storeTbl.st_id
LEFT JOIN shiftTbl ON userProfilesTbl.wa_id = shiftTbl.wa_id
LEFT JOIN userAssessmentTbl ON userProfilesTbl.UserId = userAssessmentTbl.UserId
LEFT JOIN myTbl ON userAssessmentTbl.tt_id = myTbl.tt_id
LEFT JOIN setsTbl ON trainingTbl.s_id = setsTbl.s_id
WHERE userProfilesTbl.st_id=@st_id AND userProfilesTbl.wa_id=@wa_id AND DATEPART(m,t_date) = @m_date AND DATEPART(yyyy,t_date) = @y_date ORDER BY surname ASC"
'AND t_date=@t_date
Dim cmd As SqlCommand = New SqlCommand(query, conn)
conn.Open()
cmd.Parameters.AddWithValue("@st_id", myLblStore.Value().ToString)
cmd.Parameters.AddWithValue("@wa_id", myLblShift.Value().ToString)
cmd.Parameters.AddWithValue("@m_date", ddlMonth.SelectedValue().ToString())
cmd.Parameters.AddWithValue("@y_date", ddlYear.SelectedValue().ToString())
Dim dr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
Dim dt As DataTable = New DataTable()
Dim dt2 As DataTable = New DataTable()
dt.Load(dr)
dt2 = GetInversedDataTable(dt, "surname", "setName", "o_id", "", True)
GridView1.DataSource = dt2
GridView1.DataBind()
Catch ex As SqlException
' handle error
Catch ex As Exception
' handle error
Finally
conn.Close()
End Try
End Sub
Regards,
Charan
I-Weedy
Member
67 Points
239 Posts
Re: Filter Datatable GridView with DropDownList
Nov 28, 2012 04:39 PM|LINK
No this didnt work!
It allowed me to select both the month and year in the DropDownLists but failed to display anything in the GridView on select!
No errors displayed
aarsh
Participant
1547 Points
435 Posts
Re: Filter Datatable GridView with DropDownList
Nov 29, 2012 02:04 PM|LINK
Where did you put the code that chaaraan suggested ? It should be in the event handler of the drop downlist's you wanna use as filter or the button click event if you are using a button to trigger the filter oprtaion of the gridview.
aarsh
Participant
1547 Points
435 Posts
Re: Filter Datatable GridView with DropDownList
Nov 30, 2012 05:03 PM|LINK
Any luck ?