Tuesday, August 18, 2009

ASP.Net/General - Value of Variable Changes

ASP.Net/General - Value of Variable Changes
Hello,

I have a form with a variable addNew as Boolean. I have 2 buttons "Add" and Save". I change the valus of addNew in Add button event and make it as True. Focus is on text boxes, I enter date and click on Save button to save the data entered. But in save event method, the value of addNew is False only. Except these 2 places and Page_Load, I am not using addNew anywhere. I can't make out then ho the value of addNew turns to False from True which was lastly set in Add method. I also have a listbox whose AutoPost property is set to True.



' List SelectedIndexChange event
Protected Sub locationsList_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles locationsList.SelectedIndexChanged
' Retrieve data from Datasource
' And show contents in respective text boxes
MsgBox(locationsList.SelectedValue + " Index = " + locationsList.SelectedIndex.ToString)
'dim loc As LocationClass = (LocationClass) locationsList.SelectedItem

End Sub

' Save Button Event
Protected Sub saveBtn_Click(ByVal sender As Object, ByVal e As EventArgs) Handles saveBtn.Click
If (addNew) Then
' Insert into
locNameTxt.Enabled = False
SqlDataSource1.Insert()
Else
'Update Record
SqlDataSource1.Update()
End If
addNew = False
End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
' Want the values to set only once
If (Not Page.IsPostBack) Then
addNew = False
locationsList.SelectedIndex = 0
End If
End Sub

' Add button Event
Protected Sub PrepareToAdd(ByVal sender As Object, ByVal e As EventArgs) Handles addLocBtn.Click
addNew = True
locNameTxt.Enabled = True
locNameTxt.Focus()
Return
End Sub

I also want to retrieve data from sqldatasource on list's indexchange. I can retrieve the index number and field value. Can I retrieve that row from the datasource. The select statement is "Select * from Locations"

Would be glad if anyone can help me out. Any help is appreciated.

Thanks



View Full Details...............................

No comments:

Post a Comment