Posts

Showing posts from August, 2008

Loop through Generic List

Generic Lists were such a big deal for me.  I love the ability to have all my db items in one place ... in classes in separate data layer and returning neatly to my page when I need them.  Binding Generic Lists to data controls was easy but I had to figure looping through it when the occasion came that I was not directly binding but using the values in other ways.   Example below to Loop through a Generic List '''Class is maindata '''Function that builds my list is getLCOpen - I am passing it three variables For Each x As LC_data.maindata In LC_data.maindata.getLCOpen("", "", 0)           'do something here with data Next  

CLEAR FORM ELEMENTS/loop through page controls

Handy routine for clearing out all of your textbuttons or making all of your panels visible   Sub resetBtn_Click(Sender As Object, E As EventArgs) Dim myForm As Control = Page.FindControl("myform") << put in name of your form on your page Dim ctl As Control For Each ctl In myForm.Controls 'Clears Textbox Types   If ctl.GetType().ToString().Equals("System.Web.UI.WebControls.TextBox") Then              CType(ctl, TextBox).Text = ""   End If   Next ctl End Sub

Generic List Single Item

Working with Generic Lists in a data class has been quite rewarding.  I still occasionally return Datasets but typically everything I need to do can be done using the List items.   It is a breeze to return entire list, datasets or in this case just an integer .... the project is program_data, class is pdMain and public function is getProgramInfo with 2 parameters.  I just want the Fiscal Week value  - function typically returns an entire list of data but I just want the first record and one item - I would do it something like this:   'GENERIC LIST - SINGLE ITEM Dim temp As String = program_Data.pdMain.getProgramInfo("HMD", "")(0).FiscalWeek lblFiscalWeek.Text = temp

Code Flunkie - Everything .Net

New Blog .... just for dotnet snippets. I set it up to put all those little snippets I like to drop in here and there - figured I would share. The pieces of code that you rarely use but never can find when you need it ..... Some of my snippets are old and I will try to revise as I add them.