Blog Stats
  • Posts - 8
  • Articles - 0
  • Comments - 3
  • Trackbacks - 0

 

Wednesday, March 25, 2009

Pass Multiple values to Modal Window

A JavaScript object can be of great help when you need to pass multiple values to a Modal Window. E.G.

 var objArgs = new Object();
 objArgs.Value1 = "Value 1";
 objArgs.Value2 = 2;
 var modalWindowFeatures = 'dialogHeight:600px;dialogWidth:600px;scroll:no;status:no;resizable:no';
  url = 'relative/path/to/page';
  var returnValue;

  returnValue = window.showModalDialog(url,objArgs,modalWindowFeatures );

Wednesday, February 04, 2009

Subquery returned more than 1 value

"Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression"

As the error message suggests , this normally occurs when you are assigning a T-SQL variable a value within sql query and the query is returning more that one rows e.g.
Declare @var1 nvarchar(50)
' select @var1=name from table1'

Putting 'top 1' can resolve the problem  in many cases ( do check the business logic aspects):

' select top 1 @var1=name from table1'

Monday, January 26, 2009

Install Visual Studio 2003 when Visual 2005 is intalled already

other day I had to install Visual studio.NET 2003 on my system, the problem was I had Visual Studio 2005 and 2008 with framework 2.0 and 3.5 and I did not have .NET 1.1 on it.

There were two suggetions from ppl at work:

  1. Install .NET framework 1.1 and load project in VS 2005
  2. You will need to Un install VS 2005 and 2008 and then install VS.NET 2003

After googling a little first idea did not seem workable and I was not ready to  follow the second option of starting all over. Half hour down I found a solution:

The trick is to install .NET framework 1.1 separately first and then run Visual studio 2003 installer.

-- Follow UP

VS 2003 is working fine, VS 2005 and SQL Server 2005 prompt an error on start   "unable to load file, this error could not be resolved, Please reinstall the application". It seems to work fine though.


 

 

Thursday, January 08, 2009

Scroll Div on page load

If you have a gridview/repeater control or other tabular data within a div, scroll bar appears when height  of data gets bigger than that of DIV.
If you want to scroll down to a certain position, you can use 'Element.scrollTop' property in Javascript:

document.getElementById(divWithScroll').scrollTop = PixelsToScroll;

Calculating the PixelsToScroll may vary depending on scenerio,

In my case, I wanted to scroll down to a selected row within Repeater control. Row was selected using RadioButton and page was reloaded on selection of RadioButton. So, I saved the SelectedItem.ItemIndex  in Repeater_ItemDataBound in a hidden field and using the value in Javascript like following:

PixelsToScroll = SelectedItem * 22;

where 22 is height of table row

Call OnClick Event of Button when Enter key pressed in TextBox

Problem: Say you have two Grid View controls on one page, each grid view has a TexBox and a 'search' button above it

TextBox1 btnSearch1                                       TextBox2 btnSearch2

Now if you press 'Enter' key  in TextBox1, it will trigger btnSearch1_click event and when you press 'Enter' key in TextBox2, it still triggers btnSearch1_click


Solution:  Add asp.net Panel tag and set DefaultButton property.

<asp:Panel ID="pnlSearch2" runat="server" DefaultButton="btnSearch2">
          TextBox2 btnSearch2
</asp:Panel>
 

Fixed Header for Data Repeater Control

I had a Repeater control within a div. Now when there were more records than visible within height of DIV a scroll bar appear. But, when user scrolls down, the headings ( within HeaderTemplate) would go up and not be visible.

After googling a little, I was able to find the solution on code project:

http://www.codeproject.com/KB/webforms/DataGridFixedHeader.aspx


In my case though I had a 'tr' element within 'HeaderTemplate' element ,so I applied it to like:

<tr class="ms-formlabel DataGridFixedHeader " >

Limitation:

It worked fine in IE 7, but in IE 6 the background image, if you have any in css,  would disappear on scrolling.

Monday, January 05, 2009

Debug stored procedure

It s really easy to debug a SQL sever stored procedure in Visual Studio, here are the steps:

  1. Open Server Explorer
  2. Connect to the Database which have the stored procedure that you want to debug
  3. Once you are connected to a DB, it will display DB objects in Server Explorer, Click  to expand Stored Procedures
  4. Right Click on the Stored Procedure ( that you want to debug ) 
  5. Click on 'Step Into Stored Procedure'

join in SQL update statement

I had to update value from a staging table( this might be a temp table ) into another database table. Here is how I did it using a inner join in the Update statement.

UPDATE Table1
SET Table1.Field1 = StagingTable.Field1
FROM Table1 INNER JOIN StagingTable ON Table1.Field2 = StagingTable.Field2

You can also add a where clause to this SQL:

WHERE StagingTable.Field3 IS NOT NULL


---------------------------------------------------------------------

Same way we can use JOINs in insert and delete statements
 

 

Copyright © faizanahmad