|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
can't remove listitem from ddl in loopAny ideas why this code will not remove listitems for the dropdownlist? Protected Sub CullProjects() Dim ProjectName As String If Me.gvRequestProjects.Rows.Count > 0 Then For Each row As GridViewRow In Me.gvRequestProjects.Rows ProjectName = Trim(Me.gvRequestProjects.DataKeys(row.RowIndex).Values(1).ToString) Me.ddlProjects.Items.Remove(ProjectName) Next End If End Sub ProjectName is a valid name of an item in the ddl. Using something very similar to this on a one-by-one basis and it works correctly but not in this code. Thanks, Mike Hi Mike,
might be because the indexes of the datagrid will be corrupt when you deleting items in a loop after which is joined by same collection. I've had nearly the same problem with a listbox and solved it by an opposite way. Means writing all items which are not selected in a list and bind them with the listbox AFTER the ForEach - Loop. Public Sub btn_removejob_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim lst_joblist As WebControls.ListBox Dim lic_joblist As New WebControls.ListItemCollection() Dim lst_tmpitem As WebControls.ListItem For Each lst_tmpitem In lst_joblist.Items If lst_tmpitem.Selected = False Then lic_joblist.Add(lst_tmpitem.Text) End If Next lst_joblist.DataSource = lic_joblist lst_joblist.DataBind() end sub Hope this will solve your problem. regards phil Show quoteHide quote "mharness" <bo***@hotmail.com> schrieb im Newsbeitrag news:da2dnQMoPITCluLYnZ2dnUVZ_qemnZ2d@comcast.com... > Hello, > > Any ideas why this code will not remove listitems for the dropdownlist? > > Protected Sub CullProjects() > Dim ProjectName As String > If Me.gvRequestProjects.Rows.Count > 0 Then > For Each row As GridViewRow In Me.gvRequestProjects.Rows > ProjectName = > Trim(Me.gvRequestProjects.DataKeys(row.RowIndex).Values(1).ToString) > Me.ddlProjects.Items.Remove(ProjectName) > Next > End If > End Sub > > ProjectName is a valid name of an item in the ddl. Using something very > similar to this on a one-by-one basis and it works correctly but not in > this code. > > Thanks, > > Mike >
ERROR: The state information is invalid for this page and might be corrupted
Properties do not reliably persist using CompositeControl Drop Down List issue themes Images Item has already been added. Key in dictionary SiteMap resolve question Parameter as web user control Enter text in at least one textbox Themes & CSS DetailsView without DataSource |
|||||||||||||||||||||||