none
Error editing gridview multiple filters RRS feed

  • Question

  • I am using Microsoft Visual Studio 2010 Professional, asp.net 4.0 and VB code in my project.  I have a gridview being populated by a MySQL connection manually (not using the data source).  I have 2 dropdownlists that act as filters.  The first filters by fullname and can be edited with no problem.  The second dropdownlist filter is by branch, the filter works, but when you hit the edit button, you are taken back to the original fully bound gridview (no filters applied). 

       
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

            connection.Open()
            If IsPostBack = False Then
                fillnameddl()
                fillbranchddl()
            End If

            connection.Close()

        End Sub

         Protected Sub Gridview1_RowEditing(sender As Object, e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing

            GridView1.EditIndex = e.NewEditIndex
            If GridView1.EditIndex = 0 Then
                filtername()
            Else
               
                bind()
            End If
        End Sub

    It is in the row_editing that we are having issues with the filters. Right now we have it 'working' by checking the edit index. Unfiltered, gridview1.row(0) is hidden and is a blank line in the db so a user will not be able to edit it. When filtered by name, only 1 row shows up thus our IF statement works since the editindex will always be 0. We want to add a second filter (branch) which will return multiple rows which then cause our 'edit system' not to work.

    So basically, we need to be able to get the editindex variable when filtered. But it seems that when the gridview is filtered, the editindex is always returned as 0.


            Sub filtername()
            ddlselect = ddlUserlist.SelectedItem.Text
            Dim query As String
            query = "Select * FROM newhires WHERE fullname ='" & ddlselect & "'"
            Dim myAdapter As New MySqlDataAdapter(query, connection)
            Dim ds As New DataSet
            myAdapter.Fill(ds)
            GridView1.DataSource = ds
            GridView1.DataBind()
            End Sub

            Sub filterbranch()
            ddllocation = ddlOffice.SelectedItem.Text
            Dim query As String
            query = "Select * FROM newhires WHERE branch ='" & ddllocation & "'"
            Dim myAdapter As New MySqlDataAdapter(query, connection)
            Dim ds As New DataSet
            myAdapter.Fill(ds)
            GridView1.DataSource = ds
            GridView1.DataBind()
            End Sub

            Sub bind()

            Dim query As String
            query = "Select * FROM newhires ORDER BY fullname"
            Dim myAdapter As New MySqlDataAdapter(query, connection)
            Dim ds As New DataSet
            myAdapter.Fill(ds)
            GridView1.DataSource = ds
            GridView1.DataBind()
            GridView1.Rows(0).Visible = False

            End Sub


    More code can be posted if necessary but I think these are the problem areas.

    Thanks

    • Moved by Neddy Ren Wednesday, April 13, 2011 2:40 AM asp.net issue (From:Windows Forms General)
    Thursday, April 7, 2011 9:56 PM

All replies

  • Hello,

    this forum is dedicated to Windows Forms technology while your question seems to be related to ASP.Net so you'll probably get a better help in the ASP.net forum.

    Unfortunately AFAIK moderators can not move your thread there so you will have to repost your question.

    Best regards,
    Vladimir

    Friday, April 8, 2011 12:28 AM