Bunch's Blog

One day I'll have a catchy subtitle, one day
posts - 87 , comments - 129 , trackbacks - 0

Friday, August 31, 2012

RadGrid Column Sizing

I came across this column sizing weirdness the other day. Using a RadGrid the headers looked great. The rows with the data however sized however they felt like it, usually way too small. After looking around I came across this that solved my problem. Adding the meta tag of <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> in the head section of my aspx page was what I needed.

My issue was pretty specific since I had to target IE8 for the app I was working on but it may apply to other scenarios as well.


Posted On Friday, August 31, 2012 9:54 AM | Comments (0) |

Tuesday, July 17, 2012

Oracle and Looping Through Columns

I recently had to write a stored procedure that validated some data in a staging table. Looping through the records was pretty straight forward in Oracle using a loop (way easier than the SQL Server version). However there was set of columns in the table that were all the same type but different values that needed to be checked. To clarify I had a table setup like this:

ID  Name  Number  Position1  Position2  Position3

The ID is just an integer PK value, Name would be a players name, Number their jersey number and then Position1 - 3 the different positions the player knows how to play (like shortstop, second base, left field, etc.).

To start with I create my outer loop that I would use to check their Name and Number along with getting the various Position values.

for players in (select p.ID, p.Name, p.Number, p.Position1, p.Position2, 
                    from stage_players p) loop

After checking the Name and Number I needed now to loop through the three possible Positions for the player's record or loop through that record's columns. To do this I setup an inner loop like this.

for positions in (select players.Position1 as pos from dual
                       select players.Position2 as pos from dual
                       select players.Position3 as pos from dual) loop

Now I can use this loop to check each positions.pos to make sure they are valid.


Posted On Tuesday, July 17, 2012 3:24 PM | Comments (0) |

Tuesday, May 29, 2012

SSMS Slow To Save

When using SSMS 2008 I found it to be really slow when trying to save a file, even a small one with just some simple SELECT statements on it. The symptoms were the flashing save disk icons in the lower right corner and selecting the location to save in the Save File dialog would hang each time I picked a location (e.g. Libraries, a folder). This was the first I had seen anything like this where it was really, really slow. It ended up that a server had died last week and I was still mapping a drive to it. SSMS was still trying to connect to it causing the slow down (further information here and here). Once I removed that the save functionality worked like it should.


Posted On Tuesday, May 29, 2012 1:52 PM | Comments (0) |

Friday, May 25, 2012

New Window Via JavaScript Clears Parent

This is not a new item at all but I came across it recently. For an app I had been using some JavaScript like:

javascript:window.open(someurl.aspx here)

to open a new window via a button. That bit of code had been working great in several other apps. Then in one app that same code decided to open the new window correctly while clearing the parent of everything but [object]. The fix ended up being simple, change the javascript to:

javascript:void(window.open(someurl.aspx here);

Then it worked like I thought it should.

Tags: ,

Posted On Friday, May 25, 2012 1:28 PM | Comments (0) |

Wednesday, May 23, 2012

BoundField Formatting

If you have a GridView that uses BoundFields but does not display line breaks or a lot of spaces quite right here is a way to get around that. This example uses a GridView with one BoundField that uses a DataField of comments. The comments are stored in a database and entered from another page which displays the comments properly in a textbox with all the spaces and line breaks you intended. The trick to get a BoundField to show those items is to take the item and replace the \r\n with a <br /> and the spaces with &nbsp. Also you need to set the HtmlEncode property of the BoundField to false.

This example shows the data being returned to a DataView which is the DataSource for the GridView.

The GridView:

<asp:GridView ID="gvComments" runat="server" AutoGenerateColumns="false" >
      <asp:BoundField DataField="comments" HtmlEncode="false" />

The code (assumes the DataView dv is already filled):

int i = 0;
foreach (DataRow dr in dv.Table.Rows)
   string comment = dr.Field<string>(6);
   comment = comment.Replace(" ", "&nbsp;");
   comment = comment.Replace("\r\n", "<br />");
   dv.Table.Rows[i][6] = comment;

Tags: ,

Posted On Wednesday, May 23, 2012 4:24 PM | Comments (0) |

Tuesday, May 15, 2012

Old SQL, Top and a Variable

I came across this the other day. Using SQL 2000 I could not get a Top statement to work with a variable. I had forgotten that only with SQL 2005 and higher could you do this trick. I found a good way around it, you can read about it here. Anyway this works on SQL 2000:

declare @top int
set @top = 5

set rowcount @top
 select Some_ID
 from tblStuff
set rowcount 0

The code above would return the first five records from tblStuff. For any of the newer SQL Server version you can simply use the @top variable in Top like:

select top (@top) Some_ID
from tblStuff


Posted On Tuesday, May 15, 2012 1:48 PM | Comments (0) |

Tuesday, May 8, 2012

Searching SQL Server Objects

I came across this tool the other day and found it to be very useful. In the past if I needed to search within all the stored procedures or views in a database I would use some SQL to run a query using sysobjects and syscomments. That worked well but this is a bit slicker. The tool is redgate's SQL Search and it is available (for now at least) as a free stand alone tool. You can download it here.

It supports SQL 2005 and later and I found it to integrate with the SSMS IDE well. It will add a red binocular SQL Search icon in your tool bar. Clicking that will open a nice tab with the searching fields. You can easily search for some value within a view then switch to a stored procedure. I found it to be really useful when setting up a test database and I needed to search for names of objects that might have changed for the new test environment. You search for a value then double click the item on the list which opens the item within Object Explorer.


Posted On Tuesday, May 8, 2012 9:41 AM | Comments (0) |

Friday, April 13, 2012

ORA-00900 Super Easy Fix (for some cases)

Here is a really easy fix for some ORA-00900 errors. Well at least the one I saw the other day. This was something that I did not come across when searching either. I found lots of other ideas on what the problem might be but not the fix. Since I am fairly new to PL/SQL (TSQL only for a long time) this one stumped me for a while. Until I asked someone and they saw the error in about two seconds.

When using the Command Window to add a view I was receiving an ORA-00900 error. So I checked that everything the view was referencing was there and that the permissions looked OK. The code for the view was fairly simple and it ran just fine in a regular SQL Window. It ended up that the Command Window did not like the space I had between the list of items in the select before the from.


                               <--- does not like the empty line
from tblSomething


from tblSomething

I will just chalk that up to my familiarity with PL/SQL.


Posted On Friday, April 13, 2012 4:25 PM | Comments (0) |

Wednesday, March 28, 2012

Finding Buried Controls

This post is pretty specific to an issue I had but still has some ideas that could be applied in other scenarios. The problem I had was updating a few buttons so their Text values could be set in the code behind which had a method...

Posted On Wednesday, March 28, 2012 2:27 PM | Comments (0) |

Tuesday, March 6, 2012

RadGrid PagerStyle in Code Behind

Recently I ran into an issue where the paging text in a RadGrid control needed to be customizable. In my case I was specifically looking at the "Page size" and "xx items in yy pages" text. Getting around it for the "Page size" was a snap. If your RadGrid is called rgTest one line would do it:

rgTest.PagerStyle.PageSizeLabelText = "your text here";

The "xx items in yy pages" was a bit trickier, but still handled in one line of code.

rgTest.PagerStyle.PagerTextFormat = "{4} {5} things in {1} my pages";

The tricky part was determining which items to use, there are five in total ({1} through {5}). The {4} needs to be first otherwise the rest will not show up. A good guide (but not for my particular situation) is found here.

Tags: ,

Posted On Tuesday, March 6, 2012 3:56 PM | Comments (0) |

Powered by: