Link to home
Start Free TrialLog in
Avatar of ApexCo
ApexCoFlag for United States of America

asked on

Using a boolean for conditional updates, why isn't this working?

I've got a bit of an issue and I can't figure it out. I'm doing some updates on a grid and due to the way the update works from the RadGrid I'm trying to implement the following.

I've declared a boolean Dim bRelCode As Boolean and I've got  a selectedindexchanged event firing on a dropdown as follows:

    Public Sub dropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
        'Load the label using the selected value of first dropdownlist.

        'first reference the edited grid item through the NamingContainer attribute
        Dim editedItem As GridEditableItem = CType(CType(sender, DropDownList).NamingContainer, GridEditableItem)

        Dim lblRelCode As Label = CType(editedItem("TemplateColumnRelCode").FindControl("RelCode"), Label)

        Dim table As DataTable = DataSourceHelperLK.GetDataTable(("SELECT code_ID FROM contrid WHERE ci_title = '" _
        + CType(editedItem("TemplateColumnRelCodeDesc").FindControl("DropDownList1"), DropDownList).SelectedItem.Text + "'"))

        'Dim lstRelCode As DataList = CType(editedItem("TemplateColumnRelCode").FindControl("lstRelCode"), DataList)
        Dim grid As GridView = CType(editedItem("TemplateColumnRelCode").FindControl("gridview1"), GridView)
        Dim lbl As Label = CType(editedItem("TemplateColumnRelCode").FindControl("RelCode"), Label)

        grid.DataSource = table
        grid.DataBind()
        lbl.Visible = False
        bRelCode = True

    End Sub

Now that sets my boolean to true and everything is fine at this point, but when I go to do the update portion it seems my boolean is losing the value assigned to it in the dropdown changed event. And when I get to this bit of code in the update sub;

            If bRelCode = True Then
                grid = TryCast(eeditedItem.FindControl("Gridview1"), GridView)
                lblRelCode = CType(grid.Rows(Convert.ToInt32(0)).Cells(0).FindControl("lblRelCode"), Label)
            Else
                lblRelCode = CType(eeditedItem.FindControl("RelCode"), Label)
            End If

My bRelCode = false and the wrong piece of that if..then is firing.

Ideas?
ASKER CERTIFIED SOLUTION
Avatar of dstanley9
dstanley9

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial