yaip Posted October 23, 2003 Posted October 23, 2003 I've got a DropDownList and a DataGrid on my Webform and I've got the following code: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here If Not Me.IsPostBack Then Me.SqlDataAdapter1.Fill(Me.DataSet11) Me.DataGrid1.DataBind() Me.DropDownList1.SelectedIndex = 0 End If End Sub Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged Me.DataView1.RowFilter = "Substring(FirstName,1,1) = '" & Me.DropDownList1.SelectedItem.Value & "'" End Sub My DropDownList has A,B,C,D, etc as items. Whenever I select a new item from my DropDownList I want my DataGrid to be updated accordingly. It is not happening. I also chaned my RowFilter to LIKE instead of Substring. It also works fine on Window forms. It is the Web form that is giving me this problem. What am I doing wrong? :confused: Quote
Moderators Robby Posted October 23, 2003 Moderators Posted October 23, 2003 the DataView1.RowFilter should be DataView1.RowFilter = "SomeColumnName = '" & Me.DropDownList1.SelectedItem.Value & "'" Quote Visit...Bassic Software
yaip Posted October 23, 2003 Author Posted October 23, 2003 I got different results Her is the code I modified: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here If Not Me.IsPostBack Then Me.SqlDataAdapter1.Fill(Me.DataSet11) Dim rf As String = "Substring(FirstName,1,1) ='" & Me.DropDownList1.SelectedItem.Value & "'" Me.DataView1.RowFilter = rf With Me.DataGrid1 .DataBind() .AllowSorting = True End With Me.DropDownList1.SelectedIndex = 0 Me.Cache("ds2") = Me.DataSet11.Copy Else Me.DataSet11.Clear() Me.DataSet11 = Me.Cache("ds2") End If End Sub Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged Dim rf As String = "Substring(FirstName,1,1) ='" & Me.DropDownList1.SelectedItem.Value & "'" Me.DataView1.RowFilter = rf With Me.DataGrid1 .DataBind() .AllowSorting = True End With I suspected that during postback the values are not being retained in my DataSet. So i cached the value and when I put the debugger on, I could see that the count for DataSet (DataSet.tblStudents.count) was now a non-zero value (telling me that the DataSet value are being retained). The RowFilter value, works the first time and the grid is properly displayed with the FirsName filter working as I want it to. However, if I select a different value in my DropDownList, the RowFilter fails. and the DataView's count is 0. Telling me there is nothing selected in the DataView. Quote
yaip Posted October 23, 2003 Author Posted October 23, 2003 I guess what I am saying is the RowFilter works the first time but does not work the second time. Quote
yaip Posted October 23, 2003 Author Posted October 23, 2003 Here is what I found This is the code that seems to wrking. Though I don't know if it is th right way to do it. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here If Not Me.IsPostBack Then Me.SqlDataAdapter1.Fill(Me.DataSet11) Me.Cache("ds") = Me.DataSet11.Copy Me.Cache("dv") = Me.DataView1 Dim rf As String = "Substring(FirstName,1,1) ='" & Me.DropDownList1.SelectedItem.Value & "'" Me.DataView1.RowFilter = rf With Me.DataGrid1 .DataBind() .AllowSorting = True End With Me.DropDownList1.SelectedIndex = 0 Else Me.DataView1 = Me.Cache("dv") Me.DataSet11 = Me.Cache("ds") End If End Sub Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged Dim rf As String = "Substring(FirstName,1,1) ='" & Me.DropDownList1.SelectedItem.Value & "'" Me.DataView1.RowFilter = rf With Me.DataGrid1 .DataSource = Me.DataView1 .DataBind() .AllowSorting = True End With End Sub As you can see, I am caching the DataView object too. I wonder how it can be impemented with a TreeView control.:D Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.