Archive for December, 2010

Gridview Basics

Thursday, December 30th, 2010

If you’re new to Gridviews this should be a helpful article.

You have a limited amount of space horizontally to display your gridview, but someone (boss, client, etc.) has indicated that their is additional information they need to see.  Instead of forcing all of the data into a small space and creating a multi-lined field, which is unappealing…add a button that will display the additional info somewhere else on the page, within a model dialog window or message box.

The Button control has the following properties; CommandName and CommandArgument.  They can be used in the following way:
<asp:Button id=”action” runat=”server” text=’text’ CommandName=”ShowInfo” CommandArgument=’<%#Eval(”ID”) %>’ />

The code behind file will have the following subroutine:
Protected Sub GRIDVIEW_NAME_RowCommand(ByVal sender As Object, ByVal e As CommandEventArgs) Handles GRIDVIEW_NAME.RowCommand
Response.Write(”TEST = ” & e.CommandName)
Response.Write(”TEST = ” & e.CommandArgument)
End Sub

The system will fire the  subroutine and will pass the CommandName and CommandArgument values as parameters.  You can have several buttons with several different CommandNames, which will allow you to expand the functionality.

Protected Sub gvProcessed_RowCommand(ByVal sender As Object, ByVal e As CommandEventArgs) Handles gvProcessed.RowCommand
Response.Write(”TEST = ” & e.CommandName)
End Sub

SQL Select Statement: Random, Fixed Number of Distinct Records

Monday, December 13th, 2010

I recently ran into a development process that required SQL generated records to solve the following problem.

- Select ‘N’ number of records
- The records needed to random
- There could not be any duplicates
- There must be the set number of records returned

Here is the solution I came up with to solve this problem.

declare @numberOfRecords bigint

Select TOP (@numberOfRecords) field1 from
(Select * from table1 where id=’3′) a
group by field1 order by NewID()

Like what you see? Let's talk.

Monday - Friday, 8:30am - 8:00pm EST.
Call us at 617-229-7210
*Required Fields