Feb 16 2006

eBay Selling Starter Kit for VB.NET In Town!!

Category: ASP.NET 2.0 - GeneralBil@l @ 11:43

You can now download the Ebay Starter Kit from: http://developer.ebay.com/windows/starterkits/

There is also an article at MSDN that helps you start your way with that starter kit, check it at:
Introduction to the eBay Selling Starter Kit


Hope that helps,



Feb 15 2006

Dynamic Sql Query with Output Parameters

Category: Databases & SQLBil@l @ 14:13

I had a previous post on how to use Dynamic Sql Queries.

Today I had the need to create a Stored Procedure that returns an Output Parameter, where the value of the output parameter is set inside the Dynamic Query.

So here is a sample Stored Procedure that shows how to do s:

CREATE PROCEDURE GetNotificationIdByCustomerId
    @CustomerId    INT,
    @GroupId    INT,
    @NotificationId    INT OUTPUT
    DECLARE @strQuery NVARCHAR(4000)
    DECLARE @parameterList NVARCHAR(4000)

    SELECT @strQuery = 
            TOP 1 @NotificationId = NotificationId  
        WHERE (CustomerId = @CustomerId)  AND (Processed = 0) '

    IF ( @GroupId <> -1 )
        SELECT @strQuery = @strQuery  + N' AND (GroupId = @GroupId)'
    SELECT @parameterList =   N'@NotificationId INT OUTPUT, @CustomerId INT, @GroupId INT'            
    EXECUTE SP_EXECUTESQL @strQuery, @parameterList, @NotificationId OUTPUT, 
                @CustomerId = @CustomerId, @GroupId = @GroupId

I need to get @NotificationId, which is set inside the dynamic query, I then supply a list of parameters inside the @parameterList, where I specify the output parameter.

Hope that helps,



Feb 14 2006

Working with DotNetNuke Custom Modules

Category: DotNetNukeBil@l @ 17:36

I have recently started working with DotNetNuke, this is my first post in the DotNetNuke category, so expect I will be posting more often here in this section.

To start with, I would like to point all DNN developers about a great link where they can download CodeSmith Templates for creating DotNetNuke Modules.

You can visit: VS.NET 2003 Project Templates for DotNetNuke to download the templates you can use to create a new module. 

You can alos check this great article, that helps you out develop your first Module in DotNetNuke 3.x, located at: DotNetNuke Random Image Module - Tutorial

That was my start with Custom Modules or Private Assemblies in DotNetNuke.

Enjoy DotNetNuking !!



Feb 14 2006

Build a Data Access Layer in less than 15 minutes with CodeSmith

Category:Bil@l @ 17:08

Erick Smith, the founder of CodeSmith, posted a great article on how to create a Data Access Layer in a very quick time.

You can check the article at: Build a Data Access Layer in less than 15 minutes

Hope that helps you,



Feb 12 2006

DataList Show/Hide Table Rows

Category: ASP.NET 1.x | ASP.NET 2.0 - GeneralBil@l @ 00:31

In the last few days, I was working on a Custom DotNetNuke Module, which is called ContactUs, which I will be using in one of the projects currently under my hands.

I wanted to list all entries of the ContactUs form that are stored in the database. So I decided to use the DataList, in which I place my own Table inside the ItemTemplate.

There are some fields in the ContactUs form that might be empty or null. So I didn't want to show the ROW inside the table for each NULL field in the database.

Here how I did it:

<asp:datalist id="dlstContactUs" runat="server" cellpadding="4" datakeyfield="itemId">
        <table cellSpacing="0" cellPadding="2" border="0">
            <tr vAlign="top" runat="server" id="trCompany" Visible='<%# IsNull(DataBinder.Eval(Container.DataItem,"Company")) %>'>

Watch the DarkGreen areas above.

In the code-behind, this is the IsNull method that I am using:

public bool IsNull(object item)
    if ((item.ToString() != null) && (item.ToString() != String.Empty))
        return true;
        return false;

Hope that helps,


Tags: ,

Feb 11 2006

CountryList SQL Script

I am working on a Custom DotNetNuke module. I wanted to have a DropDownList of all the countries in the world.

I had to google a little bit to find all the countries available, which I beleive are 222 countries.

I wanted to share with you the SQL Script I created.

You can download this script from the Files Area.

When you run this script using the Sql Query Analyzer, it will create the following:

  • regionList table
  • countryList table
  • Insert 222 countries into the countryList table categorized by regions located at regionList table.

I am sure you will need this script in your work some time.

If there is still any country not listed, please let me know so that I update the script

For DNN Custom Modules' developers, I found later on that there is a dll in the bind folder of the DNN installation called CountryListBox, don't know what it is, but I guess it is related to country list or so.

Hope this helps,



Tags: , ,

Feb 9 2006

Popup Window inside Code-Behind

Category: ASP.NET 1.xBil@l @ 14:14

Opening a pop up windows from code-behind has been the topic of many many questions on the ASP.NET forums. I once created a control in two versions for ASP.NET 1.1 and 2.0, that helps developers by calling a simple method, providing it with some paramters, and here you go, opening a popup windows very easily, no javascript no nothing, just simple VB.NET/C# function calls.

I had that control on my previous website, as a free downloadable control, I decided today to place it again on this blog, since there are still many developers on the ASP.NET forums, asking on how to do so.

Visit the Files Area on my blog and download the control and use it for free.

Enjoy Popupping !! :)




Feb 8 2006

Access Selected GridViewRow in GridView

Category: ASP.NET 2.0 - GeneralBil@l @ 08:10


I was working last night around 3:00 AM, and I found out that in my GridView Column's list, I have added a TemplateField of type LinkButton with CommandName=”EditRec”, in such a way, when the Edit link button is clicked, I want to access the selected GridViewRow, then populate a web form on the same page, and without having to show the “Update” and “Cancel” buttons on the GridView.

I did that, but the problem was now how to access the GridViewRow in the RowCommand method?

I used the “SelectedRow” property but I kept having “Object Reference not ....” I didn't know in fact.

I tried to use GridView1.Rows[e.CommandArgument], but the DataKey I set for the GridView was of type String, so cannot use that either.

I finally was able to use the following and it works fine for me:

if (e.CommandName.Equals("EditRec"))
            string MediaIndex = e.CommandArgument.ToString();

            // Get the last name of the selected author from the appropriate
            // cell in the GridView control.
            GridViewRow selectedRow = (GridViewRow)(((Control)e.CommandSource).NamingContainer);

            string _mediaType   = selectedRow.Cells[0].Text;
            string _CheckOut    = selectedRow.Cells[1].Text;


The way the code works if as follows:

e.CommandSource -> LinkButton
((Control)e.CommandSource).NamingContainer -> GridViewRow

Then, simply use the Cells property inside the GridViewRow to access all cells.

Hope that Helps,



Feb 8 2006

Good Links to Share

Category: ASP.NET 1.x | ASP.NET 2.0 - GeneralBil@l @ 08:01

I would like to share with you the following two links, which I beleive are good and useful.



Tags: ,

Feb 8 2006

URL Mapper in ASP.NET 2.0

Category:Bil@l @ 07:54

Url Rewriting with Regex for ASP.NET 2.0

A new feature in ASP.NET 2.0 is it's built-in url rewriting support. When i looked into this new feature i found out it lacked regular expressions support, wich is really the point of an Url Mapper. ScottGlu at his blog, explains the reason why the ASP.NET team didn't implemented this feature. Basically they realized that a full featured version would want to take advantage of the next IIS 7.0 new features, specially the support for all content-types (images and directories).

Anyway, it's really simple to implement a Url Rewriting Module with Regex support in ASP.NET. I wrote a quick and simple HttpModule for this. The whole magic is done within a few lines within the HttpModule:

 1 public void Rewrite_BeginRequest(object sender, System.EventArgs args) { 
 2      string strPath = HttpContext.Current.Request.Url.AbsolutePath; 
 3      UrlRedirection oPR = new UrlRedirection(); 
 4      string strURL = strPath; 
 5      string strRewrite = oPR.GetMatchingRewrite(strPath);
 6       if (!String.IsNullOrEmpty(strRewrite)) { 
 7           strURL = strRewrite; 
 8      } else { 
 9           strURL = strPath; 
10      } 
11      HttpContext.Current.RewritePath("~" + strURL);
12 }

The code is self explanatory. When a request that is processed by the ASP.NET engine, the module checks an XML for a regex match. I've seen many Url Rewriting engines that uses Web.config to store the matching rules but i prefer using an additional XML file. The rewriting rules file look like the following:

 1 <?xml version="1.0" encoding="utf-8" standalone="yes"?>
 2 <urlrewrites>
 3      <rule name="Category Page">
 4           <url>/([a-zA-Z][\w-]{1,149})\.aspx</url>
 5           <rewrite>/Default.aspx?Category=$1</rewrite>
 6      </rule>
 7      <rule name="Item Page">
 8           <url>/([a-zA-Z][\w-]{1,149})/([a-zA-Z][\w-]{1,149})\.aspx</url>
 9           <rewrite>/Default.aspx?Category=$1&amp;Item=$2</rewrite>
10      </rule>
11 </urlrewrites>

The rule matching routine, wich is implemented in the GetMatchingRewrite() method is quite simple and lightweighted:

 1 public string GetMatchingRewrite(string URL)  {
 2      string strRtrn = "";
 4      System.Text.RegularExpressions.Regex oReg;
 6      foreach (RedirectRule oRule in Rules) {
 8           Reg = new Regex(oRule.URL);
 9           Match oMatch = oReg.Match(URL);
11           if (oMatch.Success)  {
12                strRtrn = oReg.Replace(URL, oRule.Rewrite);
13           }
15      }
16      return strRtrn;
17 }

I have uploaded a sample project that uses this rewriting engine. The HttpModule and it's helper classes are inside the App_Code folder. I hope you find this code useful, if you have any questions just leave a comment in this entry. Happy coding!