Hi guys.
i can explain for my doubt with example.see.my table have multiple type of employee details like as Managmment,Programmer,Designers,Accountants,Contra ctEmployees.Each type of department having many employee details.Now my drop down list having types of department names like that above types of department names..if i select any one type of department data wil be display in gridview format .gridview data column as employee Name,Address,Phone_No,email_address and each every row with checkboxes.gridview showing data according to select the dept.No problem. first I select Managmment type of employee grid view showing that type of employee details ,here i checked first two employee details then i go to Programmer type of employee it showing that type employee details here i want to checked two employee details using checkbox after then i click button control,so we want two plus two, four employee details values..getting values i putting in arraylist then i puttong one view state.
If we are not select dropdown list index change selecting checkbox values are getting proper. but problem is whenever i go to select dropdown list index change i mean page post back previous checked checkbox values are getting improper.
This one viewstate problem or dropdown list or gridview problem
I used arraylist stored in session state also. But no one improvement.
see my code behind..whats problem in here code tell me..
--------dropdown list selected change event--------------------------
Protected Sub Selcon_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Selcon.SelectedIndexChanged getselected()databind1 ()
setSelected()
End Sub
--------------Getting the checkbox values from gridview then put in session state-------------------
Public Sub getselected()
Dim arrayListContactGroup As New ArrayList
If Session("ArrayList") IsNot Nothing ThenarrayListContactGroup = CType(Session("ArrayList"), ArrayList)
Session.Remove(
"ArrayList")
End IfFor Each row As GridViewRow In gridview1.Rows
Dim chkselectcontacts As CheckBox = CType(row.FindControl("chksel"), CheckBox)Dim arraylistlabel As Label = CType(row.FindControl("contid"), Label)
If chkselectcontacts.Checked Then
If Not arrayListContactGroup.Contains(arraylistlabel.Text) Then
arrayListContactGroup.Add(arraylistlabel.Text)
End If
Else
If arrayListContactGroup.Contains(arraylistlabel.Text) Then
arrayListContactGroup.Remove(arraylistlabel.Text)
End If
End If
NextSession("ArrayList") = arrayListContactGroup
End Sub
-----------------checking the checkboxes are checked or unchecked from session state -----------------
Public Sub setSelected()
Dim arrayListContactGroup As New ArrayList
If Session("ArrayList") IsNot Nothing ThenarrayListContactGroup = CType(Session("ArrayList"), ArrayList)
End IfFor Each row As GridViewRow In gridview1.Rows
Dim chkselectcontacts As CheckBox = CType(row.FindControl("chksel"), CheckBox)Dim arraylistlabel As Label = CType(row.FindControl("contid"), Label)
If arrayListContactGroup.Contains(arraylistlabel.Text) Then
chkselectcontacts.Checked =
True
Else
chkselectcontacts.Checked =
False
End If
Next
End Sub
---------Final stage checkbox values are submitting to the button control-------------
Protected Sub btnsel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnsel.Click getselected()
contactsselected()
End Sub
-------------checkbox values are passed to database then retrieve to requering field data .i wrote one function in Button control ---------------
Public Sub contactsselected()
Dim arrayListContactGroup As New ArrayList
If Session("ArrayList") IsNot Nothing ThenarrayListContactGroup = CType(ViewState("ArrayList"), ArrayList)
End If
If arrayListContactGroup.Count = 0 ThenResponse.Write("
Share Your Own Experience & Expertise
We look to ensure that every question is answered by the best people with relevant expertise and experience, the best answers include multiple perspectives. Do you have relevant expertise or experience to contribute your answer to any of these commonly asked questions?