Posts

Fixed Datagrid Headers

Quick and dirty way to make Datagrid Headers stay at the top of the page while your viewers are scrolling down the page can be accomplished with a little CSS   Add this style:       .DataGridFixedHeader { POSITION : relative ;  TOP : expression(this.offsetParent.scrollTop) ; BACKGROUND-COLOR : white } Add this to your Datagrid properties:       HeaderStyle-CssClass =" DataGridFixedHeader " And Voila ... you have a header that stays in place.

Errors Errors Errors

We would always prefer to avoid all errors but if one happens we certainly want to know about it. Adding an error handler to the Global.asax file is slick - easy and works beautifully..... here is what you need: Sub Application_Error( ByVal sender As Object , ByVal e As EventArgs) Try Dim strFrom As String = System.Configuration.ConfigurationManager.AppSettings( "EmailFrom" ) Dim strTo As String = System.Configuration.ConfigurationManager.AppSettings( "EmailTo" ) Dim msg As System.Net.Mail.MailMessage Dim smtp As New System.Net.Mail.SmtpClient( " mail.yourmailserver.com " ) msg = New System.Net.Mail.MailMessage(strFrom, strTo, "Page Error My Application Name" , BuildMessage()) msg.IsBodyHtml = True smtp.Credentials = New System.Net.NetworkCredential( "Username" , "password" , " mail.myserver.com " ) smtp.Send(msg) Catch ex As Exception End Try End Sub The buildMessage Function in the global.asax...

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.