Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Dropdownlist index change event problem.

Hi guys.
i can explain for my doubt with example.see.my table have multiple type of employee details like as Mangemment,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 Mangemment type of employee grid view showing that type of employee details ,here i checked first two employee details then checkbox values put in one viewstate,then i go to Programmer type of employee it showing that type employee details here i want to checked two employee details using checkbox but what happened first two checkboxes are already checked. so view state having proper checked check box values but problem is
whenever i go to select for another type of employee details checkboxes are checked based upon order of previous checked index.

this is my problem.plz clear my problem.its very urgent.

whenever i select dropldown list viewstate values is empty . this is my problem.
[1312 byte] By [thanigaimani83] at [2007-11-11 11:58:58]
# 1 Re: Dropdownlist index change event problem.
You are either 2 things wrong.
Try Binding the datagrid on

If IsPostback Then
Your Code goes here!
End if

The other thing is that it will be best to either have a statement like this.

For Example, if you want to parse the group type via Request.QueryString, you can try the trick that I have below.

Protected Sub Dropdownlist1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Dropdownlist1.SelectedIndexChanged

Response.Redirect("YourFile.aspx?ptype=" & Dropdownlist1.SelectedValue & "")
End Sub
Emefa at 2007-11-11 23:10:39 >
# 2 Re: Dropdownlist index change event problem.
Hi Emefa

I can used gridview control.if i put page.ispostback condition viewstate value not added to current checked checkbox values.

once again i explain for my problem with my code code behind.

i checked checkbox values of dropdown list selected index changed event,values are coming from viewstate,so we want viewstate values add plus new checked checkbox values ,but if i click display button control that viewstate values are removing then new checked checkbox values are only diaplay .

see my code behind..

i can put smiles image near of where i used viewstate and i can underlined the code of viewstate values are removing( i mean previous page checked checkbox values).

Protected Sub gridview1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gridview1.PageIndexChanging

gridview1.PageIndex = e.NewPageIndex

getselected()

databind1("First_name", "asc")

setSelected()

End Sub

------

Public Sub getselected()

Dim arrayListContactGroup As New ArrayList

If ViewState("ArrayList") IsNot Nothing Then:confused:

arrayListContactGroup = CType(ViewState("ArrayList"), ArrayList)

ViewState.Remove("ArrayList")

End If

For 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

Next

ViewState("ArrayList") = arrayListContactGroup

------

Public Sub setSelected()

Dim arrayListContactGroup As New ArrayList

If ViewState("ArrayList") IsNot Nothing Then:confused:

arrayListContactGroup = CType(ViewState("ArrayList"), ArrayList)

End If

For 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

--------

Protected Sub Selcon_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Selcon.SelectedIndexChanged

getselected()

databind1(ViewState("sort"), ViewState("ascdesc"))

setSelected()

End Sub

My problem is,arraylist values(checkbox values) stored in viewstate,viewstate get the values no problem,but whenever i go to dropdown list select index change at that time we want add viewstate values and current checked checkbox values,but its doing opposite side operation i mean removing the view state value.see i can underlined that line.

I wont dropl down list value.
thanigaimani83 at 2007-11-11 23:11:45 >