Archive for the ‘Cool Code’ Category

Title Property of the @Page Directive

Monday, February 11th, 2008

Hey, did you know with .Net Framework 2.0 you can title your pages with the “Title” property in the @Page directive of the page. Make sure to add runat=”server” in the HEAD tag and that’s it. You can then remove the “TITLE” tag from the “HEAD” section. It is also code side accessible.

Binding the Data to the GridView

Thursday, October 25th, 2007

Hey if you are getting this error message:
“A call to Bind was not well formatted”

If you are trying to use something like this:

<%# Bind(”Last Name”) %>

With spaces or symbols in the name, you should use brackets [] around the name to make it work.

Like this:

<%# Bind(”[Last Name]“) %>

I hope this helps.

AJAX Calendar Extender

Monday, October 22nd, 2007

If you are going to use the AJAX Toolkit Calendar Extender you are going to have to place runat=”server” in the head tag. The control evidentally has to place stuff in the tag during the server process.

<head runat="server">

I hope this helps.

ASP.NET UpdateProgress Control

Wednesday, October 10th, 2007

I was having trouble getting my UpdateProgress Control  to actually display when I thought it should. I finally figured it out today. A little property called DisplayAfter solved the whole thing. The default is set to 500 milliseconds and if you turn that down a little bit, you should see a difference.

I set mine to 100.

Javascript: Loop Thru Datagrids

Wednesday, November 23rd, 2005

Here is some starter code in javascript that should help you loop through an APS.NET datagrid.

function SelectDataGridRow(sDataGridName) {
    var oTable;
    var oRows = new Array();
    var i;
    
    oTable = document.getElementById(sDataGridName);
    oRows = oTable.rows;        
    iRowCount = oRows.length - 1;
    
    for (i = 0; i <= iRowCount; i++)
    {
        //insert here code that you would like to preform.

    }
}

I hope this helps in some sort of way. If it does, share it with a friend.

VB.Net - Two Data Grids - Moving Rows

Thursday, October 27th, 2005

The purpose of this code is to give the illusion on the form the rows in one data grid are being moved to the other data grid. To accomplish this you will need of course a data table of some sorts to hold the data. You will also need a method that will delete the selected row from the table and another method that will insert a row into that same table.

For instance. You have a selection of baskets to place different fruit in. You want to give the user of the form functionality to be able to manipulate what fruit goes in what basket from a list of available fruit. One data grid will display the fruit currently in the selected basket. The other data grid will show the available fruit. Restricting the same fruit from being placed in the currently selected basket. The data source for the fruit in the currently selected basket is in one data table and the data source for the available fruit comes from another table.

The add and delete methods should only modify data the in the table that holds the baskets selected fruit. Each time that either add or delete method is fired it should result in the illusion of the items being removed or added to the data grids. The table with available items always has the same items always. Nothing is added or deleted from this table. It is with the code below that you will use to remove rows from the available items data table based on what is in the current data table before display.

Is this confusing enough yet?

Realize of course the following example has been abstracted and is somewhat generic. You will have to modify it to work for you and your situation. I hope it at least gives some ideas.


   Private Sub BindGrids()
       ‘Declare and Bind two data tables.  

       ‘I created two seperate bind methods for this.  

       Dim dt1 As DataTable = BindDataGrid1()
       Dim dt2 As DataTable = BindDataGrid2()  

       ‘Start looping through the first  

       For Each dr1 As DataRow In dt1.Rows
        ‘Find a matching row in data table 1  

        ‘with a matching value in data table 2  

        ‘and set found rows to a data rows collection  

        Dim dr As DataRow() = dt2.Select(dataColumnName = ” & dr1(0))  

        ‘Starting looping through the rows found  

        ‘and remove the rows out of the second data table.  

        For Each dr2 As DataRow In dr
            dt2.Rows.Remove(dr2)
        Next  

       Next  

       ‘Instantiate a data view  

       Dim dv As New DataView(dt1)  

       ‘Bind data table 1 to data grid 1  

       DataGrid1.DataSource = dv
       DataGrid1.DataBind()  

       ‘Re-instantiate data view  

       dv = New DataView(dt2)  

       ‘Bind data table 2 to data grid 2  

       DataGrid2.DataSource = dv
       DataGrid2.DataBind()
   End Sub

Hey, if this helps, share it with a friend.

Also, use at your own risk. I take no responsibility if it blows your computer to high heavens. Don’t come hunting me down and trying to sue. You have been warned.

Cool Code - Javascript - Replace Enter with Tab

Tuesday, October 4th, 2005

This code only works for IE because the event.keyCode is read-only in Mozilla and most other browsers. This simple snippet will keep the ENTER key from submitting the form in the IE browser. If you want something that will work in IE as well as other browsers that will take a lot more code and adding an event to each object on the page for the most part. If you are looking for something like that, take a look here.

//————————————
//replaces the enter key with the tab key

document.onkeydown = function
() {   if (event.keyCode == 13)
   {
      event.keyCode = 9;
   }
}
//————————————-

Cool Code - VB.Net - Property Setup to a View State Variable

Friday, September 16th, 2005

Public Property TabSelect() As Integer

    Get

        Dim tmp As Object = ViewState(“local_TabSelect”)
        If Not tmp Is Nothing Then

            Return Convert.ToInt32(tmp)
        Else

            Return 1
        End If

    End Get

    Set(ByVal Value As Integer)
        ViewState(“local_TabSelect”) = Value
    End Set

End Property