Friday, September 21, 2007

(one) Story of my Life

Labels:

Tuesday, September 11, 2007

Finding/Manipulating a child control of a FormView in C#

It's distressing that it took me over a week to get this working.

The problem: In a C# web application, I want to set the visible property of a FormView's edit button based on value of a bound data field (actually I used eval for the label I would use to hold the value).

Here's the short answer: Finding ASP.NET Child Controls....the Simple Way
The key for me was not only in the post itself, but also in an answer to a comment that suggested using the Trace functionality to discern the control tree. Once I found the control I did my evaluation and manipulation in the Page_Load.

  protected void Page_Load(object sender, EventArgs e) {
    Label EA = this.FindControl("ctl00$ContentPlaceHolder$FormView$EntryAge") as Label;
    LinkButton EB = this.FindControl("ctl00$ContentPlaceHolder$FormView$EditButton") as LinkButton;
    if (EA != null && EB != null) {
      if (Convert.ToInt32(EA.Text) < visible =" true; } else { EB.Visible = false; }
    }
  }



I use Firefox and keep a tab trail so that my searches are cumulative and I can maybe shave some time off a similar issue later. This round of R&D started with this search
2.0 DataBinding "ASP NET " -"visual basic".
(It is a stubborn, personal resentment towards the reimagining of the Visual Basic language that has driven my focus on C#.)

Working with Data in ASP.NET 2.0

Accessing and Updating Data in ASP.NET 2.0: Accessing Database Data

Accessing and Updating Data in ASP.NET 2.0: Programmatically Accessing Data using the Data Source Controls

Programmatically access data source control C#

DevASP.Net Data Source Controls in ASP.NET 2.0 Article, Samples ...

Customizing DataBinded Output in Templates

Custom html Databind formview eval C# if +"eval("

Adding and Responding to Buttons to a GridView

C# formview control manipulation +advanced

formview "(eval(" visible lang:c# (Google Code Search)
Also did a Krugle code search, but the url doesn't change :/

http://forums.asp.net/p/985573/1269322.aspx (Google Code Search Result)
c# toggle form view item template visible (Microsoft Live Search - A clear sign of desperation...)

Finding controls inside ItemTemplates inside a FormView inside a LoginView
Getting Closer...

Google Code Search Refresher
I REALLY need to brush up on my regex

ASP.NET ItemTemplates, EVAL() and embedding dynamic values into controls

Finding ASP.NET Child Controls....the Simple Way GOLD!!!

This entire process strikes me as unnecessarily convoluted. It doesn't get much more basic than the evaluation and manipulation of an object in your application, but this exercise was anything but. By this point in previous Microsoft IDE's I'd given up on they're design time controls and done everything by hand. What's different now? I have less time and higher expectations. Sucks, but it's the reality. However, my goal in this post is not to bitch about over-architected and still lacking platforms, but to hopefully save someone the time I spent hunting down what should have been a simple solution.

Labels: , ,

Monday, September 10, 2007

SQL Server 2005 Compatibility level and CROSS APPLY

As usual, it took me WAY too long to find/figure this out so I'm sharing a Summary.

The requirement: A User Defined Function that returns one row, but multiple columns. Sounds like something between a scalar and a table valued function, eh?

My first and best hit came from here... except it didn't work X@

Here's a generalized version of my code.

FUNCTION:

CREATE FUNCTION [dbo].[udf_MyUserDefinedFunction] (
@Param1 int
, @Param2 int
)
RETURNS @Params Table (
Column1 int
, Column2 int
, Column3 int
)
AS
BEGIN
DECLARE @Column1 int
DECLARE @Column2 int
DECLARE @Column3 int

SET @Column1 = (SELECT SUM(SomeIntColumn) FROM tblNumbers1 WHERE SomeColumn = @Param1 AND SomeOtherColumn = @Param2)

SET @Column2 = (SELECT
IntColumn1
+ IntColumn3
+ IntColumn4
- IntColumn9
FROM tblNumbers2 WHERE SomeColumn = @Param1 AND SomeOtherColumn = @Param2)

SET @Column3 = (@Column1/@Column3)

INSERT INTO
@Params
VALUES (
@Column1
, @Columns2
, @Column3
)

RETURN
END

-- Created Successfully --

QUERY:

SELECT
x.Column1
, x.Column2
, y.Column1
, y.Column2
, y.Column3
FROM
dbo.SomeTableOrView AS x
CROSS APPLY
dbo.udf_MyUserDefinedFunction(73, x.Column2) AS y


Messages:
.Net SqlClient Data Provider: Msg 102, Level 15, State 1, Line
Incorrect Syntax near 'x'.

The Problem? The server I'm running this code on was upgraded from SQL Server 2000 to 2005. The Compatibility level (Database Properties > Options) was set to SQL Server 2000 (80).

After hours of searching for functional examples of CROSS APPLY (which looked a lot like my code) I looked for info on the error message. This was one of the least helpful error messages I've encountered. I got hits on creating endpoints / web services but eventually stumbled on this.

PS For some reason, the second link is not working in Firefox, but has no problem in IE. WTF?
Well, you already know the answer, I just want to give proper credit.

Labels: , ,

Tuesday, September 04, 2007

Google Reader Update?


Nothing on the Google Reader Blog (yet), but after what seemed like a short outage, the feed counters have jumped by a factor of 10. Now it's much easier to see how far behing I've fallen behind on any of my 175+ feeds(subscriptions). Here's a look at clip of what I see now:

Labels: