« September 2006 | Main

October 23, 2006

New Blog

Hi everyone. I want to let you know that I have moved to a different location. My new blog can now be found here. I had imported all the posts and comments to the new website so nothing will be lost. Please update your favorites and your rss feeds.

Thank you and as always... Happy Programming!

08:37 AM | Permalink | Comments (0)

October 18, 2006

Maintaining Collection Property State for Web Custom Controls

My blog has moved. Please go to: http://jstawski.com/archive/2006/10/18/Maintaining-Collection-Property-State-for-Web-Custom-Controls.aspx

I have dealt with this issue twice already, once being yesterday, and both times I found it very hard to find the solution. Therefore, i'm posting about it, not only for people to find the solution to their problem, but also for a reminder for me.

Anyway, developing Web Custom Controls is cool. It saves you time by using code reusability and the best part is Visual Studio makes it very easy to create one. Whenever you have properties on a control, by default they are shown on the property window of the control and whenever you set a property for the first time it adds an attribute to the tag element of that control. For example, if you set the visible property of a textbox to false at design time and then switch to the source, the textbox tag now looks like this:
:TextBox ID="TextBox1" runat="server" Visible="False"></asp:TextBox>
(note the Visible attribute.) This is the way Visual Studio implements state for design time properties. The good news is you don't have to do anything special on your control for that to work. The not so good news is that this works for primitive types like Strings, Integer, Booleans or even Enums, but not so well with collections. In order for this to work, you have to set an attributes at the property level of the control:

Happy Programming!

02:54 PM | Permalink | Comments (0)

October 05, 2006

More Control Over GridView Column

My blog has moved. Please go to: http://jstawski.com/archive/2006/10/05/More-Control-Over-GridView-Column.aspx

In response to the many comments/questions regarding the post on GridView, HyperLinkField, and JavaScript: what the #%$@! I decided to extend it and show how you can have total control over a column with the GridView.

Whenever you need to do something that is not out of the box with the GridView, like adding RadioButtons, Adding JavaScript, etc you can use the <asp:TemplateField> In there you have total control as far as what you want to insert on that column. Following the issue with the JavaScript from my other post there is an example on how to do achieve the same results:
    <%#"<a href=""javascript:MM_openBrWindow('../images/elevations/" & Eval("Column1") & "','img" & Eval("Column2") & "','');"">" & Eval("Column1") & "</a>"%>

02:19 PM | Permalink | Comments (6)

October 04, 2006

ExecuteNonQuery Always Returns -1

My blog has moved. Please go to: http://jstawski.com/archive/2006/10/04/ExecuteNonQuery-Always-Returns-_2D00_1.aspx

Whenever you want to execute a sql statement that shouldn't return a value or a record set the ExecuteNonQuery should be used. So if you want to run an update, delete, or insert statement, you should use the ExecuteNonQuery. ExecuteNonQuery returns the number of rows affected by the statement. This sounds very nice, but whenever you use the SQL Server 2005 IDE or Visual Studio to create a Stored Procedure it adds a small line that ruins everything. That line is: SET NOCOUNT ON; This line turns on the NOCOUNT feature of SQL Server, which "Stops the message indicating the number of rows affected by a Transact-SQL statement from being returned as part of the results" and therefore it makes the SP always to return -1 when called from the application (in my case a web app).

In conclusion, remove that line from your SP and you will now get a value indicating the number of rows affected by the statement.

Happy Programming!

11:55 AM | Permalink | Comments (41)