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(" <script language=javascript> alert('Please select atleast one contact') </script>")

Exit Sub

ElseFor Count As Integer = 0 To arrayListContactGroup.Count - 1

arraystringcontact += arrayListContactGroup(Count).ToString +

","

Next

arraystringcontact = arraystringcontact.Substring(0, arraystringcontact.LastIndexOf(","))

ds = objclient.contactsRetriveToDiary(Request.Cookies(

"Master")("AgentId"), Request.Cookies("Master")("BrokerId"), arraystringcontact)

constring =

"<div id='divid'><table>"For i As Integer = 0 To ds.Tables(0).Rows.Count - 1

constring = constring &

"<tr><td>" & "</td><td>" & ds.Tables(0).Rows(i).Item("Name").ToString & "</td><td>" & ds.Tables(0).Rows(i).Item("Address").ToString & "</td><td>" & ds.Tables(0).Rows(i).Item("Phone").ToString & "</td><td>" & ds.Tables(0).Rows(i).Item("email").ToString & "</td></tr>" & "<br>"

Next

constring = constring &

"</table></div>"

divcontact.InnerHtml = constring


End IfSession("KK") = arraystringcontact

End Sub

--------------------

whats problems in my code,whenever i change dropdown selected index change getselected function not getting proper selected checkbox values ...

reply me

Can you please modify your post to include code tags? Additionally, I am not entirely sure if I understand what the code is supposed to be doing, versus what it is doing.

Also, there is a WHOLE lot of whitespace in your code. I don't know if the forum did that, but it really makes things that much harder to read...

Edited 3 Years Ago by pritaeas: Fixed formatting

This article has been dead for over six months. Start a new discussion instead.