Redirect to previous page

ViewState[“PrevPage”] = Request.UrlReferrer.ToString();

Block page while asynchronous post back asp.net

Method I:

Style:

<style type=”text/css”>
.hide
{
display: none;
}
.show
{
display: inherit;
}
.progressBackgroundFilter
{

position: absolute;
top: 0px;
bottom: 0px;
left: 0px;
right: 0px;
overflow: hidden;
padding: 0;
margin: 0;
background-color: #000;
filter: alpha(opacity=40);
opacity: 0.5;
z-index: 1000;
}
.processMessage
{
border-color: #808080;
border-style: solid;
border-width: 0px 1px;

position: absolute;
font-family: arial,helvetica,clean,sans-serif, Verdana;
font-size:12px;
font-weight:normal;
color:#000066;
top: 45%;
left: 43%;
padding: 10px;
width: 18%;
z-index: 1001;
background-color: #fff;
}
</style>

 

In ASPX Source:

<asp:UpdateProgress ID=”updPrgsBaselineTab” runat=”server”>
<ProgressTemplate>
<div id=”progressBackgroundFilter”>
</div>
<div id=”processMessage”>
<table width=”100%”>
<tr style=”width: 100%”>
<td style=”width: 100%”>
Please Wait……….
</td>
</tr>
<tr style=”width: 100%”>
<td style=”width: 100%” align=”center”>
<img src=”images/activity.gif” alt=”Loading…” />
</td>
</tr>
</table>
</div>
</ProgressTemplate>
</asp:UpdateProgress>

—————————————————-

Method II:

Style:

.PrProgress
{

display: block;
position: absolute;
padding: 2px 3px;
}
.PrContainer
{
border: solid 1px #808080;
border-width: 1px 0px;
}
.PrHeader
{

background: url(Images/sprite.png) repeat-x 0px 0px;
border-color: #808080 #808080 #ccc;
border-style: solid;
border-width: 0px 1px 1px;
padding: 0px 10px;
color: #000000;
font-size: 9pt;
font-weight: bold;
line-height: 1.9;
white-space:nowrap;
font-family: arial,helvetica,clean,sans-serif;
}
.PrBody
{
background-color: #f2f2f2;
border-color: #808080;
border-style: solid;
border-width: 0px 1px;
padding: 10px;
}

In ASPX Source:

<div id=”pnlPopup” style=”display: none;”>
<div id=”innerPopup”>
<div>
Loading, please wait…</div>
<div>
<img width=”220px” height=”19px” src=”images/activity.gif” alt=”loading…” />
</div>
</div>

 

Source: http://www.codekicks.com/2010/06/how-to-block-aspnet-page-while-ajax.html

 

CheckboxList Selected items in javascript Asp.net

function CheckBoxSelectedCount()

{

var tableBody = document.getElementById(‘<%=ChkBox_Zones.ClientID %>’);

var status=0;

for(var i=0;i<tableBody.cells.length;i++)

{

var checkBox = document.getElementById(tableBody.id + ‘_’ + [i]);

if(checkBox!=null && checkBox.checked){ numItemsChecked = numItemsChecked + 1; }

 }

if(numItemsChecked ==0)

{

alert (‘Please Select Zones’);

tableBody.focus();

return false ;

}

return true ;

}

String Array to ArrayList – without looping- C#

string[] strAry = new string[] { “a”, “b”, “c” };
ArrayList AryLst = new ArrayList();
AryLst.AddRange(strAry);

SQL Split function

Function  I:

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

create FUNCTION [dbo].[SplitByComma] ( @StringInput VARCHAR(8000) )
RETURNS @OutputTable TABLE ( [String] VARCHAR(10) )
AS
BEGIN

DECLARE @String    VARCHAR(10)

WHILE LEN(@StringInput) > 0
BEGIN
SET @String      = LEFT(@StringInput,
ISNULL(NULLIF(CHARINDEX(‘,’, @StringInput) – 1, -1),
LEN(@StringInput)))
SET @StringInput = SUBSTRING(@StringInput,
ISNULL(NULLIF(CHARINDEX(‘,’, @StringInput), 0),
LEN(@StringInput)) + 1, LEN(@StringInput))

INSERT INTO @OutputTable ( [String] )
VALUES ( @String )
END

RETURN
END

–select * from [SplitByComma] (‘rav,ft,sfd,sdfd’)

Select a Row in A Gridview by Clicking Anywhere on it

Add a GridView, Bind values in Gridview.

C#:

protected void GridView_CustomerDetails_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes[“onmouseover”] = “this.style.cursor=’hand’;this.style.textDecoration=’underline’;”;
e.Row.Attributes[“onmouseout”] = “this.style.textDecoration=’none’;”;

e.Row.Attributes[“onclick”] = ClientScript.GetPostBackClientHyperlink(this.GridView_CustomerDetails, “Select$” + e.Row.RowIndex);
}

}
catch (Exception)
{

throw;
}
}

 

 

Source:

http://www.geekzilla.co.uk/view9FC28EE6-ACB0-4F51-BFE4-38B0B10134D5.htm

http://www.aspmessageboard.com/showthread.php?t=230982

Search a keyword in whole DataBase

How to search all columns of all tables in a database for a keyword?

While browsing the SQL Server newsgroups, every once in a while, I see a request for a script that can search all the columns of all the tables in a given database for a specific keyword. I never took such posts seriously. But then recently, one of my network administrators was troubleshooting a problem with Microsoft Operations Manager (MOM). MOM uses SQL Server for storing all the computer, alert and performance related information. He narrowed the problem down to something specific, and needed a script that can search all the MOM tables for a specific string. I had no such script handy at that time, so we ended up searching manually.

That’s when I really felt the need for such a script and came up with this stored procedure “SearchAllTables”. It accepts a search string as input parameter, goes and searches all char, varchar, nchar, nvarchar columns of all tables (only user created tables. System tables are excluded), owned by all users in the current database. Feel free to extend this procedure to search other datatypes.

The output of this stored procedure contains two columns:

– 1) The table name and column name in which the search string was found
– 2) The actual content/value of the column (Only the first 3630 characters are displayed)

Here’s a word of caution, before you go ahead and run this procedure. Though this procedure is quite quick on smaller databases, it could take hours to complete, on a large database with too many character columns and a huge number of rows. So, if you are trying to run it on a large database, be prepared to wait (I did use the locking hint NOLOCK to reduce any locking). It is efficient to use Full-Text search feature for free text searching, but it doesn’t make sense for this type of ad-hoc requirements.

Create this procedure in the required database and here is how you run it:

–To search all columns of all tables in Pubs database for the keyword “Computer”
EXEC SearchAllTables ‘Computer’
GO

Here is the complete stored procedure code:


CREATE PROC SearchAllTables
(
	@SearchStr nvarchar(100)
)
AS
BEGIN

	-- Copyright © 2002 Narayana Vyas Kondreddi. All rights reserved.
	-- Purpose: To search all columns of all tables for a given search string
	-- Written by: Narayana Vyas Kondreddi
	-- Site: http://vyaskn.tripod.com
	-- Tested on: SQL Server 7.0 and SQL Server 2000
	-- Date modified: 28th July 2002 22:50 GMT


	CREATE TABLE #Results (ColumnName nvarchar(370), ColumnValue nvarchar(3630))

	SET NOCOUNT ON

	DECLARE @TableName nvarchar(256), @ColumnName nvarchar(128), @SearchStr2 nvarchar(110)
	SET  @TableName = ''
	SET @SearchStr2 = QUOTENAME('%' + @SearchStr + '%','''')

	WHILE @TableName IS NOT NULL
	BEGIN
		SET @ColumnName = ''
		SET @TableName =
		(
			SELECT MIN(QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME))
			FROM 	INFORMATION_SCHEMA.TABLES
			WHERE 		TABLE_TYPE = 'BASE TABLE'
				AND	QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME) > @TableName
				AND	OBJECTPROPERTY(
						OBJECT_ID(
							QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME)
							 ), 'IsMSShipped'
						       ) = 0
		)

		WHILE (@TableName IS NOT NULL) AND (@ColumnName IS NOT NULL)
		BEGIN
			SET @ColumnName =
			(
				SELECT MIN(QUOTENAME(COLUMN_NAME))
				FROM 	INFORMATION_SCHEMA.COLUMNS
				WHERE 		TABLE_SCHEMA	= PARSENAME(@TableName, 2)
					AND	TABLE_NAME	= PARSENAME(@TableName, 1)
					AND	DATA_TYPE IN ('char', 'varchar', 'nchar', 'nvarchar')
					AND	QUOTENAME(COLUMN_NAME) > @ColumnName
			)

			IF @ColumnName IS NOT NULL
			BEGIN
				INSERT INTO #Results
				EXEC
				(
					'SELECT ''' + @TableName + '.' + @ColumnName + ''', LEFT(' + @ColumnName + ', 3630)
					FROM ' + @TableName + ' (NOLOCK) ' +
					' WHERE ' + @ColumnName + ' LIKE ' + @SearchStr2
				)
			END
		END
	END

	SELECT ColumnName, ColumnValue FROM #Results
END


Source: http://vyaskn.tripod.com/search_all_columns_in_all_tables.htm#

=============================================================================


Overview

  • Transact SQL; TSQL; Search entire database for a value
  • This script/stored procedure when created, then executed, will search every table in the database it has been created on, for the search value the user passes it (can handle wildcard

Instructions

  1. EDIT the use quotemaster statement to refer to your own database, i.e. use Northwind;
  2. Then, uncomment the use and go statements immediately following the BEGIN SCRIPT line
  3. Then, select and run (can highlight and press F5 in Query Analyzer) all lines from BEGIN SCRIPT to END SCRIPT (end of this page)
  4. To see it in action, once you have done steps 1 - 3 above.
    1. Edit the database name in the USAGE section below, to refer to your own database
    2. Edit the '%FUELSC%' search term param value (below) with the search term you are looking for---you CAN use wildcards
    3. Select the three lines in the USAGE section below, and execute (can press F5 to execute highlighted text in Query Analyzer)

Note

A large database could take several minutes to search through
  • USAGE (once stored proc has been created in your db):
  • use quotemaster; --replace with database name you are using, and UNCOMMENT
  • go --UNCOMMENT
  • exec dbo.GetRecordsWithValInAnyFld '%FUELSC%'; --replace paramater value with search term, and UNCOMMENT
  • BEGIN SCRIPT
  • use quotemaster; --EDIT THIS LINE, TO REFER TO THE DATABASE YOU WILL PLACE SCRIPT IN --go --THEN, UNCOMMENT THIS LINE (go), AND RUN all FROM PREVIOUS LINE To END

Code

if exists (select * from sysobjects where id = object_id(N'dbo.GetRecordsWithValInAnyFld') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop proc dbo.GetRecordsWithValInAnyFld; go create procedure dbo.GetRecordsWithValInAnyFld (@ValToFind varchar(500)) AS ----------------------------------------------------------------------------------------------------- -- Procedure Name-     dbo.GetRecordsWithValInAnyFld() -- Function Gets Columns/Fields that belong to name passed in -- Wildcard (%) can be used -- Input Params @ValToFind varchar(500): term (can use wildcards) to match more loosely -- Output Params Recordset -- Return Value 1 => If Successful -- number => In case of error return the error number with text -- Date 09/28/2005 -- Author Aendenne C. Armour -- Modification Log: -- Version___Modified by_________Mod Date___Summary of Modifications -- 1.0_______Aendenne C. Armour__9/28/05_____None: Initial Version -- x.0_______Aendenne C. Armour__4/2/08______To fix prior edits, and to account for other data types ----------------------------------------------------------------------------------------------------- declare @RowCount int, @Error int, @errTxt varchar(255); select @RowCount = 0, @Error = 0; declare @objName varchar(150); set @objName = 'dbo.GetRecordsWithValInAnyFld'; set nocount on; set transaction isolation level read uncommitted; create table #dbTbls ( TblName varchar(300) ); insert into #dbTbls (TblName) select o.[Name] as TblName from sysobjects o with(nolock) where o.type = 'U' order by TblName; create table #TblFlds ( TblName varchar(300), FldName varchar(300)--, --DataType varchar(100) ); insert into #TblFlds (TblName, FldName)--, DataType) select o.name as TblName, '[' + c.name + ']' as FldName    --,o.Type as ObjTypeAbbr, t.Name as DataType from syscolumns c with(nolock) inner join sysobjects o on c.id = o.id inner join systypes t on c.xusertype = t.xusertype where o.type = 'U' and t.name in ('varchar', 'char', 'nvarchar', 'nchar') order by TblName, FldName; declare @tbl varchar(300), @fld varchar(300); declare @where varchar(7000); declare @sql varchar(8000); create table #tmpVal ( val varchar(300) ); --select * from #dbTbls --select * from #TblFlds while exists(select TblName from #dbTbls) begin set @where = ' where '; insert into #tmpVal (val) select top 1 TblName as val from #dbTbls; select @tbl = val from #tmpVal; truncate table #tmpVal; set @fld = null; while exists(select FldName from #TblFlds where TblName = @tbl) begin insert into #tmpVal (val) select top 1 FldName from #TblFlds where TblName = @tbl;select @fld = val from #tmpVal; truncate table #tmpVal;set @where = @where + @fld + ' like + @ValToFind + or 'delete from #TblFlds where TblName = @tbl and FldName = @Fld;end if @fld is not nullbeginset @where = left(@where, len(@where) - 3); --remove last OR--got where clause, get records:set @sql = 'if (select count(*) from ' + @tbl + ' ' + @where + ') > 0';set @sql = @sql + ' select + @tbl + as TblName, * from ' + @tbl + ' ' + @where;if len(@sql) >= 7999 set @sql = 'select ' + @tbl + ' as TblName, CHECK TABLE MANUALLY; TOO MANY COLUMNS as WARNING';exec(@sql);--print @sql;enddelete from #dbTbls where TblName = @tbl;if (select count(TblName) from #dbTbls) <= 0break;end--select * from #tmpVal;drop table #dbTbls;drop table #TblFlds;drop table #tmpVal;select @Error = @@error, @RowCount = @@rowcount;if @Error <> 0beginset @errTxt = 'Exception: ' + @objName + ' occured; Main Select Statement'; raiserror(@errTxt, 1, 2); end -- go grant exec on dbo.GetRecordsWithValInAnyFld to public; go
http://it.toolbox.com/wiki/index.php/Get_Records_from_ANY_table_in_a_Database_Matching_Specified_Value