Using a boolean for conditional updates, why isn't this working?
Posted on 2007-08-06
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
lbl.Visible = False
bRelCode = True
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)
lblRelCode = CType(eeditedItem.FindControl("RelCode"), Label)
My bRelCode = false and the wrong piece of that if..then is firing.