Page view counter

Ignore case when checking for selected value in drop down list

Last post 03-06-2008 6:08 AM by boydd_uk. 3 replies.

Sort Posts:

  • Ignore case when checking for selected value in drop down list

    12-05-2006, 4:53 PM
    • Loading...
    • cecook05
    • Joined on 06-13-2006, 9:27 PM
    • Posts 147
    • Points 323

     I need to set the selected value in a drop down list to match the value from a database record so that the record can remain the same or be changed before submitting an update.  How can I get the control to ignore the case of the text when setting the selected value? If my database record value doesn't match the entries in the drop down list exactly, I don't get a match. The only way I can get it to work is if I convert both side to upper or lower case.  How can I get it to ignore the case?

     

        Protected Sub Branches_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles Branches.ItemDataBound
            If e.Item.ItemType = ListItemType.EditItem Then
                Dim tbID As TextBox = CType(e.Item.FindControl("tbID"), TextBox)
                Dim objBranch As New Branch
                Dim ds As New DataSet
                objBranch = objDataAccess.getBranch(tbID.Text)
                Dim LinkButtonDelete As LinkButton = CType(e.Item.FindControl("LinkButtonDelete"), LinkButton)
                Dim ddlEditRegion As DropDownList = CType(e.Item.FindControl("ddlEditRegion"), DropDownList)
                ds = objDataAccess.getRegions
                ddlEditRegion.DataSource = ds.Tables(0)
                ddlEditRegion.DataTextField = ds.Tables(0).Columns("Region").ColumnName.ToString
                ddlEditRegion.DataValueField = ds.Tables(0).Columns("Region").ColumnName.ToString
                ddlEditRegion.DataBind()
                ddlEditRegion.Items.Insert(0, "")

                ddlEditRegion.SelectedValue = objBranch.Region.ToString.ToUpper
                Utilities.CreateConfirmBox(LinkButtonDelete, _
                "Delete Branch?")
            End If
        End Sub

  • Re: Ignore case when checking for selected value in drop down list

    12-05-2006, 5:30 PM

    You can do it normal, but it wouldn't match up sometimes. it's better if you make a lower or upper case reference to it. for example: 

            Dim tofind As String = "tofind".ToLower
            Dim tmp As String = ListBox1.items(A).text.toLower
            If tmp = tofind Then
                ' It matched
            End If
    
     

    Specializing in ASP.NET 2.0
  • Re: Ignore case when checking for selected value in drop down list

    12-13-2006, 12:54 PM
    Answer
    • Loading...
    • cecook05
    • Joined on 06-13-2006, 9:27 PM
    • Posts 147
    • Points 323

    Converting  both sides to upper before doing the compare solved the problem.

    Protected Sub Branches_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles Branches.ItemDataBound
            If e.Item.ItemType = ListItemType.EditItem Then
                Dim tbID As TextBox = CType(e.Item.FindControl("tbID"), TextBox)
                Dim objBranch As New Branch
                Dim ds As New DataSet
                objBranch = objDataAccess.getBranch(tbID.Text)
                Dim LinkButtonDelete As LinkButton = CType(e.Item.FindControl("LinkButtonDelete"), LinkButton)
                Dim ddlEditRegion As DropDownList = CType(e.Item.FindControl("ddlEditRegion"), DropDownList)
                ds = objDataAccess.getRegions
                ddlEditRegion.DataSource = ds.Tables(0)
                ddlEditRegion.DataTextField = ds.Tables(0).Columns("Region").ColumnName.ToString
                ddlEditRegion.DataValueField = ds.Tables(0).Columns("Region").ColumnName.ToString
                ddlEditRegion.DataBind()
                ddlEditRegion.Items.Insert(0, "")
                Dim itemRegion As New ListItem
                'Dim strTmp As String
                For Each itemRegion In ddlEditRegion.Items
                    If itemRegion.Value.ToString.ToUpper = objBranch.Region.ToString.ToUpper Then
                        ddlEditRegion.SelectedValue = itemRegion.Text
                    End If
                Next
                'ddlEditRegion.SelectedValue = objBranch.Region.ToString.ToUpper
                Utilities.CreateConfirmBox(LinkButtonDelete, _
                "Delete Branch?")
            End If
        End Sub

  • Re: Ignore case when checking for selected value in drop down list

    03-06-2008, 6:08 AM
    • Loading...
    • boydd_uk
    • Joined on 09-18-2007, 5:19 AM
    • Posts 7
    • Points 4

    This seems a pretty ugly solution.  Is there a better way??

    drpArea.DataSource = myDataSet

    drpArea.DataTextField = "Area"

    drpArea.DataValueField = "Area"

    drpArea.DataBind()

     

    Your would think all you had to do was set drpArea.DataTextValue = "Area".ToUpper, but this doesn't work.  I can't believe the only way to do this is set a loop up.  It seems clunky to me.   Sometimes I think to myself have languages actually moved on? I was doing this kinda of thing in the 80's.  Forgive the fustration.  I just find it difficult that I've spent half and hour trying to do something that should be far easier in my humble opinion.

     

Page 1 of 1 (4 items)