31 July 2009 0 Comments

Random woes

I hate code like this:   void ProductsListView_ItemEditing(Object sender, ListViewEditEventArgs e)   {     ListViewItem item = ProductsListView.Items[e.NewEditIndex];     Label dateLabel = (Label)item.FindControl( “DiscontinuedDateLabel” );     if (String.IsNullOrEmpty(dateLabel.Text))       return ;     //Verify if the item is discontinued.     DateTime discontinuedDate = DateTime.Parse(dateLabel.Text);     if (discontinuedDate < DateTime.Now)     {       Message.Text = “You cannot edit a discontinued item.” ;       e.Cancel = true ;       ProductsListView.SelectedIndex = -1;     }         } Indexing into the item dictionary to find the correct row to edit, then finding specific controls and casting them really sucks, there must be a better way.

Original post: 
Random woes

If you liked this post, buy me a Coffee.

Leave a Reply