Prepare Table From StringArray

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER function [dbo].[PrepareTableFromStringArray](@strArray nvarchar(1000))

RETURNS @tbl TABLE
(Id int)

AS

BEGIN

DECLARE @Num int
DECLARE @Pos int
DECLARE @NextPos int
DECLARE @Name nvarchar(256)

SET @Num = 0
SET @Pos = 1
WHILE(@Pos <= LEN(Cast(@strArray as varchar(100))))
BEGIN
SELECT @NextPos = CHARINDEX(N',', Cast(@strArray as varchar(100)), @Pos)
IF (@NextPos = 0 OR @NextPos IS NULL)
SELECT @NextPos = LEN(@strArray) + 1
SELECT @Name = RTRIM(LTRIM(SUBSTRING(Cast(@strArray as varchar(100)), @Pos, @NextPos - @Pos)))
SELECT @Pos = @NextPos+1

Insert Into @tbl
Values(CAST(@Name AS int))
End

Return

END

ASP.NET Questions

How to create dynamic Gridview ?
Many times we have the requirement where we have to create columns dynamically.
This article describes you about the dynamic loading of data using the DataTable as the datasource.
Details of the Grid
Let?s have a look at the code to understand better.
Create a gridview in the page,
Drag and drop the GridView on to the page
Or
Manually type GridView definition in the page.
public partial class _Default : System.Web.UI.Page
{
#region constants
const string NAME = "NAME";
const string ID = "ID";
#endregion
protected void Page_Load(object sender, EventArgs e)
{
loadDynamicGrid();
}
private void loadDynamicGrid()
{
#region Code for preparing the DataTable
//Create an instance of DataTable
DataTable dt = new DataTable();
//Create an ID column for adding to the Datatable
DataColumn dcol = new DataColumn(ID ,typeof(System.Int32));
dcol.AutoIncrement = true;
dt.Columns.Add(dcol);
//Create an ID column for adding to the Datatable
dcol = new DataColumn(NAME, typeof(System.String));
dt.Columns.Add(dcol);
//Now add data for dynamic columns
//As the first column is auto-increment, we do not have to add any thing.
//Let's add some data to the second column.
for (int nIndex = 0; nIndex < 10; nIndex++)
{
//Create a new row
DataRow drow = dt.NewRow();
//Initialize the row data.
drow[NAME] = "Row-" + Convert.ToString((nIndex + 1));
//Add the row to the datatable.
dt.Rows.Add(drow);
}
#endregion
//Iterate through the columns of the datatable to set the data bound field dynamically.
foreach (DataColumn col in dt.Columns)
{
//Declare the bound field and allocate memory for the bound field.
BoundField bfield = new BoundField();
//Initalize the DataField value.
bfield.DataField = col.ColumnName;
//Initialize the HeaderText field value.
bfield.HeaderText = col.ColumnName;
//Add the newly created bound field to the GridView.
GrdDynamic.Columns.Add(bfield);
}
//Initialize the DataSource
GrdDynamic.DataSource = dt;
//Bind the datatable with the GridView.
GrdDynamic.DataBind();
}
}

What types of data validation events are commonly seen in the client-side form validation?
Required Field Validator

In A Page I have grid view with Options of select and delete using hyperlink when I am selecting any one of then it has to open another page how can it
Ans 1: You can have template column for select and delete instead of the databound column. In which you can mention the destination page where you need to navigate.
Ans 2: Using RowDataBound event, you can add attribute to the select and delete hyperlink like:
e.Row.Cells(CellPosition).Controls(0).Attributes.Add("OnClick","return fnJavascriptFunction()")
e.Row.Cells(CellPosition).Controls(0).Attributes.Add("OnClick","return fnJavascriptFunction('"& If any argument &"')").


Web service support a) Data set b) dataReader c) both of above d) none of above
a) Data set

ASP Objects

1. Session Object
2. Application Object
3. Server Object
4. Request Object
5. Response Object
6. Object Context
7. Error Object

Session Object
The Session object carries values needed by a single client over the entire session, which may be several pages.
Collections
Contents contains all the non-object session variables.
StaticObjects contains all the session objects.
Properties
CodePage is used to specify the page that defines the character set.
LCID specifies the location identifier to be used.
SessionID returns a numerical session number.
Timeout specifies the time, in minutes, until the session timeout.
Methods
Abandon causes the session object to be destroyed on completion of the current page.
Contents.Remove(item) removes the item from the Contents collection. item is either a string or an integer representing an index number.
Contents.RemoveAll removes all items from the Contents collection.
Events
Session_OnEnd occurs when a session ends, either by Abandon or a timeout.
Session_OnStart occurs when a new session is created.

Application Object
The Application object is used to share data among several users visiting the same group of pages. Only one instance of the Application object is created per application, and it is shared among all the clients accessing that application.
Collections
Contents contains all the non-object application variables.
StaticObjects contains all the application's objects.
Methods
Contants.Remove(item) removes the item from the Contents collection. item is either a string or an integer representing an index number.
Contents.RemoveAll removes all items from the Contents collection.
Lock prevents all other clients from modifying values in the Application object.
Unlock releases the lock and allows other clients to modify values in the Application object.
Events
Application_OnStart occurs when an application is started before the session starts.
Application_OnEnd occurs when the application quits, after all the sessions have ended.

Server Object
The Server object provides access to some basic tools on the server.
Properties
ScriptTimeout specifies the amount of time, in seconds, a script will be allowed to run before timing out.
Method
CreateObject(componentname) is used to instantiate a server component.
Execute(path) executes an ASP page as though it were part of the calling page. This is more flexible than server-side includes because the filename can be dynamically generated.
GetLastError() returns an instance of the ASPError object that describes the last error.
HTMLEncode(string) encodes string so that the browser will not interpret it as HTML.
MapPath(path) maps the specified virtual path, either a relative one or an absolute one, into a physical path.
Transfer(path) transfers control to another ASP page without creating a separate object context.
URLEncode(string) applies encoding rules so that the string may be put safely into the query string.

Request Object

The Request object is used to access data that the client sent when it requested the current page.
Collections
ClientCertificate contains certification values sent by the client.
Cookies is used to read in the values of cookies that were sent in with the request.
Cookies(name).HasKeys allows you to find out whether the specified cookie has keys.
Form contains the values entered into a form that uses the POST method.
QueryString contains the values passed to the page on the query string. (or from a form using the GET method)
ServerVariables contains the values of the environment variables.
Properties
TotalBytes specifies the number of bytes sent in the client's request.
Methods
BinaryRead retrieves the data sent by the client in a POST request and stores it into a special kind of array called a SafeArray.

Response Object
The Response object is used to send output to the client. It also allows you to control how and when the output is sent.
Collections
Cookies is used to set cookie values.
Cookies(name).Domain allows you to specify that only a particular domain can access the cookie.
Cookies(name).Expires allows you to set the date that the cookie expires. If it is not set, the cookie will expire when the session ends.
Cookies(name).HasKeys allows you to find out whether the specified cookie has keys.
Cookies(name).Path allows you to specify that only a particular path can access the cookie. The default of this is the application path.
Cookies(name).Secure allows you to specify whether extra precautions are taken to ensure the security of the cookie.
Properties
Buffer specifies whether buffering is turned on.
CacheControl specifies whether proxy servers are able to cache the page.
Charset(name) appends the name of the character set (specified by name) to the content-type header.
ContentType is used to specify the HTTP content type for the output. Default is text/HTML.
Expires specifies the length of time, in minutes, before the cached version of the page expires.
ExpiresAbsolute specifies the date and time when the cached version of the page expires.
IsClientConnected is a Boolean value that indicates whether the client is still connected to the server.
Pics(label) will add label to the PICS-label response header.
Status is the value of the server's status line.
Methods
AddHeader name, value adds an HTML header with the specified name and value.
AppendToLog string adds string to the end of the server query log entry.
BinaryWrite data writes data to the HTTP output without performing any character conversion.
Clear deletes all the buffered output that has not been sent.
End halts execution of the script and sends all buffered output.
Flush sends all the buffered output and clears the buffer.
Redirect path tells the client to make a request for the page specified by path.
Write string writes to the HTTP output.

ObjectContext Object
The ObjectContext object is used to link ASP and the Microsoft Transaction Server.
Methods
SetAbort aborts the transaction.
SetComplete declares that the transaction should complete, overriding any prior use of SetAbort.
Events
OnTransactionAbort occurs if the transaction is aborted.
OnTransactionCommit occurs after the transaction commits.

ASPError Object
The ASPError object was introduced in IIS 5.0. It allows you to obtain information about errors that have occurred in the script.
Properties
ASPCode returns a string with the error code.
ASPDescription is a long string that describes the error that occurred.
Category returns a string indicating whether the error is from the scripting language, ASP, or an object.
Column returns the column number responsible for the error.
Description is a short string that describes the error that occurred.
File returns a string indicating the name of the file responsible for the error.
Line returns the line number responsible for the error.
Number returns the error number returned by a COM component.

ASP.NET

ASP.NET (originally called ASP+) is the next generation of Microsoft's Active Server Page (ASP), a feature of their Internet Information Server (IIS). Both ASP and ASP.NET allow a Web site builder to dynamically build Web pages on the fly by inserting queries to a relational database in the Web page. ASP.NET is different than its predecessor in two major ways: it supports code written in compiled languages such as Visual Basic, C++, C#, and Perl, and it features server controls that can separate the code from the content, allowing WYSIWYG editing of pages. Although ASP.NET is not backwards compatible with ASP, it is able to run side by side with ASP applications. ASP.NET files can be recognized by their .aspx extension.