0% found this document useful (0 votes)
11 views16 pages

Unit 5

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views16 pages

Unit 5

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Application Domains: -

You can use the following C# code snippet to retrieve information about the current domain.

AppDomain applicationDomain = AppDomain.CurrentDomain;


Console.WriteLine("Application Domain Name : {0}",
AppDomain.CurrentDomain.FriendlyName);
Console.WriteLine("Application Domain Id : {0}", AppDomain.CurrentDomain.Id);

The AppDomain class pertaining to the System namespace can be used to create app domains.
It contains a set of overloaded static methods that can be used to create an app domain. You
can use the following C# code example to create an app domain and then load and execute an
assembly in it:

AppDomain applicationDomain = System.AppDomain.CreateDomain("MyAppDomain");


applicationDomain.ExecuteAssembly(@"D:\MyApp.exe");

You can use the Unload method of the AppDomain class to unload an app domain as shown
in the code snippet given below:

AppDomain.Unload(applicationDomain);
Here’s the complete source code for your reference:

using System;
namespace AppDomainDemo
{
class Program
{
static void Main(string[] args)
{
AppDomain applicationDomain =
System.AppDomain.CreateDomain("MyAppDomain");
applicationDomain.ExecuteAssembly(@"D:\MyApp.exe");
Console.WriteLine("Press any key to unload the
application domain...");
Console.ReadKey();
AppDomain.Unload(applicationDomain);
}
}
}
Remoting
.NET remoting is an architecture which enables communication between different application
domains or processes using different transportation protocols, serialization formats, object
lifetime schemes, and modes of object creation. Remote means any object which executes
outside the application domain. The two processes can exist on the same computer or on two
computers connected by a LAN or the Internet. This is called marshalling (This is the process
of passing parameters from one context to another.), and there are two basic ways to marshal
an object:
• Marshal by value: the server creates a copy of the object passes the copy to the client.
• Marshal by reference: the client creates a proxy for the object and then uses the proxy
to access the object.
Comparison between .NET Remoting and Web services: -

Ex: -
RemoteClass
using System;
using System.Collections.Generic;
using System.Text;

namespace remoteclass
{
public class xx:MarshalByRefObject
{
public int sum(int a, int b)
{
return a + b;
}
}
}
Remote Server
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

namespace remoteserver
{
class Program
{
static voidMain(string[] args)
{
TcpChannel ch=new TcpChannel(8085);
ChannelServices.RegisterChannel(ch);

RemotingConfiguration.RegisterWellKnownServiceType(typeof(remoteclass.xx),"rahul",We
llKnownObjectMode.Singleton);
Console.Write("Sever is Ready........");
Console.Read();
}
}
}
Remote Client using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data; using
System.Drawing; using System.Text;
using System.Windows.Forms; using
System.Runtime.Remoting; using
System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

namespace remoteclient
{
public partial class Form1 : Form
{
//TcpChannel ch = new TcpChannel();
remoteclass.xx obj = new remoteclass.xx(); public
Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, System.EventArgs e)
{
//ChannelServices.RegisterChannel(ch);
obj =
(remoteclass.xx)Activator.GetObject(typeof(remoteclass.xx),"tcp://localhost:8085/rahul");
int x = Int32.Parse(textBox1.Text); int y = Int32.Parse(textBox2.Text);
textBox3.Text = (obj.sum(x, y)).ToString();
}
}
}
Leasing and Sponsorship
.NET manages the lifecycle of objects using garbage collection. .NET keeps track of memory
allocation and objects accessed by all the clients in the app domain. When an object becomes
unreachable by its clients, the garbage collector eventually collects it. If the objects are in the
same app domain as the clients, garbage collection functions fine. In fact, even in the case of
a client in one app domain accessing an object in a different app domain in the same process,
garbage collection still works, because all app domains in the same process share the same
managed heap. In the case of remote objects accessed across processes and machines,
however, the strategy breaks down because the object may not have any local clients. In this
case, if garbage collection were to take place, the garbage collector would not find any
references to the object and would deem it garbage, even though there are remote clients (on
other machines, or even in separate processes on the same machine) who wish to use the
object. The rest of this section addresses this challenge.

In the following discussion, a "remote object" is an object in a different process. The core
piece of the .NET remoting architecture designed to address this problem is called leasing and
sponsorship. The idea behind leasing is simple: each server object accessed by remote clients
is associated with a lease object. The lease object literally gives the server object a lease on
life. When a client creates a remote server object (that is, actually creates it, rather than
connects to an existing instance), .NET creates a lease object and associates it with the server
object. A special entity in .NET remoting called the lease manager keeps track of the server
objects and their lease objects. Each lease object has an initial lease time. The clock starts
ticking as soon as the first reference to the server object is marshaled across the app domain
boundary, and the lease time is decremented as time goes by. As long as the lease time doesn't
expire, .NET considers the server object as being used by its clients. The lease manager keeps
a reference to the server object, which prevents the server object from being collected in case
garbage collection is triggered. When the lease expires, .NET assumes that the server object
has no remaining remote clients. .NET then disconnects the server object from the remoting
infrastructure. The server object becomes a candidate for garbage collection and is eventually
destroyed. After the object is disconnected, any client attempt to access it results in an
exception of type RemotingException, letting the client know the object has been
disconnected. This may appear strange at first, because the object may very well still be alive.
.NET behaves this way because otherwise, the client's interaction with the remote object will
be nondeterministic. If .NET allowed remote clients to access objects past their lease time, it
would work some of the time but would fail in those cases in which garbage collection had
already taken place.

But what about those cases where there are still some remote clients who would like to keep
the server object alive after its lease expires? The smart thing to do is to contact such clients
and ask them to extend the lease, or, in .NET terminology, to sponsor the lease. Clients that
wish .NET to contact them when a server object's lease expires need to provide .NET with a
special sponsor object. When the time comes, .NET will contact the sponsor object, giving it a
chance to extend the lease.
.NET Coding Design Guidelines:
A code standard is essential for maintaining code readability, consistency, and collaboration
within a development team. Following industry practices and established guidelines helps
ensure that code is easier to understand, maintain, and extend. Most projects enforce a
consistent style through code conventions. The dotnet/docs and dotnet/samples projects are
no exception. In this series of articles, you learn our coding conventions and the tools we use
to enforce them. You can take our conventions as-is, or modify them to suit your team's
needs.
We chose our conventions based on the following goals:
• Correctness: Our samples are copied and pasted into your applications. We expect
that, so we need to make code that's resilient and correct, even after multiple edits.
• Teaching: The purpose of our samples is to teach all of .NET and C#. For that reason,
we don't place restrictions on any language feature or API. Instead, those samples
teach when a feature is a good choice.
• Consistency: Readers expect a consistent experience across our content. All samples
should conform to the same style.
• Adoption: We aggressively update our samples to use new language features. That
practice raises awareness of new features, and makes them more familiar to all C#
developers.

Assemblies in C#
Assembly is an important concept in C#. It is a collection of code files that are compiled into
an executable or a Dynamic Link Library (DLL). Depending on their location and intended
use, assemblies can be divided into many categories. We will examine the various assembly
types in C# in this article.

Private Assemblies:
An Assembly that is solely used by one application is referred to as a Private Assembly. It is
typically found in the directory for the application or a subdirectory of the directory for the
programme. Private Assemblies are not intended to be shared with other applications. They
are used to store application-specific code and resources. Private Assemblies are created
when an application is compiled. When an application is compiled, all the code files and
resources that are used by the application are compiled into a single assembly. The
application's directory or a subdirectory of the application's directory will thereafter contain
this assembly. Private Assemblies are simple to deploy and use. They don't need any extra
installation or setting. They are automatically loaded by the .NET runtime when the
application starts.

Shared Assemblies:
An assembly that is used by several programmes is referred to as a shared assembly. It is
typically found in the Global Assembly Cache (GAC) or a common directory. Multiple
applications are supposed to share a shared assembly. They are used to store resources and
code that are shared by various applications. Shared Assemblies are created using the strong
name tool (sn.exe). A digital signature for the assembly is applied using the strong name tool.
The digital signature guarantees that the assembly is genuine and unaltered. The Global
Assembly Cache (GAC) houses shared assemblies. Shared assemblies are kept in the GAC,
which serves as a central repository. The GAC location is in the Windows directory (C:\
Windows\assembly). Shared assemblies are registered with the GAC using the gacutil.exe
tool. Shared assemblies require special configuration and installation. They cannot be simply
copied to the application's directory. They need to be registered with the GAC using the
gacutil.exe tool.

Satellite Assemblies:
An assembly used to store regional resources is referred to as a Satellite Assembly. It is
typically found in a subdirectory of the directory for the application or a subdirectory of the
directory for the Shared Assembly. Localized resources like strings, pictures, and audio files
are kept in satellite assemblies. Satellite Assemblies are created using the resgen.exe tool. The
resgen.exe tool is used to create a resource file (.resx) from a text file. The resource file is
then compiled into a satellite assembly using the al.exe tool. Satellite Assemblies are named
using a specific naming convention. The naming convention for satellite assemblies is as
follows:

<AssemblyName>.resources.dll

The <AssemblyName> part of the name is the name of the main assembly that the satellite
assembly is associated with. The.NET runtime automatically loads satellite assemblies when
the application first launches. The .NET runtime automatically selects the appropriate satellite
assembly based on the user's culture settings.
Dynamic Link Libraries (DLLs):
A Dynamic Link Library (DLL) is a type of assembly that contains code that can be used by
multiple applications. Similar to shared assemblies, DLLs are created with the intention of
being used by numerous applications. DLLs, however, differ from shared assemblies in that
they do not have a distinctive name. DLLs are kept in the directory of the application or a
subdirectory of the directory of the application. They can be used by multiple applications by
simply copying the DLL to the application's directory. DLLs are created using the same tools
that are used to create shared assemblies. However, DLLs do not require a strong name. They
can be signed with a digital signature, but this is optional.

Security in c#
Symmetric encryption and asymmetric encryption are performed using different processes.
Symmetric encryption is performed on streams and is therefore useful to encrypt large
amounts of data. Asymmetric encryption is performed on a small number of bytes and is
therefore useful only for small amounts of data.

Symmetric Encryption
The managed symmetric cryptography classes are used with a special stream class called a
CryptoStream that encrypts data read into the stream. The CryptoStream class is initialized
with a managed stream class, a class that implements the ICryptoTransform interface
(created from a class that implements a cryptographic algorithm), and a CryptoStreamMode
enumeration that describes the type of access permitted to the CryptoStream. The
CryptoStream class can be initialized using any class that derives from the Stream class,
including FileStream, MemoryStream, and NetworkStream. Using these classes, you can
perform symmetric encryption on a variety of stream objects.

The following example illustrates how to create a new instance of the default implementation
class for the Aes algorithm. The instance is used to perform encryption on a CryptoStream
class. In this example, the CryptoStream is initialized with a stream object called fileStream
that can be any type of managed stream. The CreateEncryptor method from the Aes class is
passed the key and IV that are used for encryption. In this case, the default key and IV
generated from aes are used.
Syntex: -
Aes aes = Aes.Create(); CryptoStream cryptStream = new CryptoStream( fileStream,
aes.CreateEncryptor(key, iv), CryptoStreamMode.Write);

After this code is executed, any data written to the CryptoStream object is encrypted using
the AES algorithm. The following example shows the entire process of creating a stream,
encrypting the stream, writing to the stream, and closing the stream. This example creates a
file stream that is encrypted using the CryptoStream class and the Aes class. Generated IV is
written to the beginning of FileStream, so it can be read and used for decryption. Then a
message is written to the encrypted stream with the StreamWriter class. While the same key
can be used multiple times to encrypt and decrypt data, it is recommended to generate a new
random IV each time. This way the encrypted data is always different, even when plain text is
the same. Ex: -
using System.Security.Cryptography;
try {
using (FileStream fileStream = new("TestData.txt", FileMode.OpenOrCreate))
{
using (Aes aes = Aes.Create())
{
byte[] key =
{
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16
};
aes.Key = key;

byte[] iv = aes.IV;
fileStream.Write(iv, 0, iv.Length);

using (CryptoStream cryptoStream =


new( fileStream,
aes.CreateEncryptor(),
CryptoStreamMode.Write))
{
// By default, the StreamWriter uses UTF-8 encoding.
// To change the text encoding, pass the desired encoding as the second parameter.
// For example, new StreamWriter(cryptoStream, Encoding.Unicode).
using (StreamWriter encryptWriter = new(cryptoStream))
{
encryptWriter.WriteLine("Hello World!");
}
}
}
}

Console.WriteLine("The file was encrypted.");


}
catch (Exception ex)
{
Console.WriteLine($"The encryption failed. {ex}"); }
The code encrypts the stream using the AES symmetric algorithm, and writes IV and then
encrypted "Hello World!" to the stream. If the code is successful, it creates an encrypted file
named TestData.txt and displays the following text to the console:
Console
The file was encrypted.
Asymmetric encryption
Asymmetric algorithms are usually used to encrypt small amounts of data such as the
encryption of a symmetric key and IV. Typically, an individual performing asymmetric
encryption uses the public key generated by another party. The RSA class is provided
by .NET for this purpose.

The following example uses public key information to encrypt a symmetric key and IV. Two
byte arrays are initialized that represents the public key of a third party. An RSAParameters
object is initialized to these values. Next, the RSAParameters object (along with the public
key it represents) is imported into an RSA instance using the RSA.ImportParameters
method. Finally, the private key and IV created by an Aes class are encrypted. This example
requires systems to have 128-bit encryption installed. Ex: - using System;
using System.Security.Cryptography;
class Class1
{
static void Main()
{
//Initialize the byte arrays to the public key information.
byte[] modulus =
{
214,46,220,83,160,73,40,39,201,155,19,202,3,11,191,178,56,
74,90,36,248,103,18,144,170,163,145,87,54,61,34,220,222,
207,137,149,173,14,92,120,206,222,158,28,40,24,30,16,175,
108,128,35,230,118,40,121,113,125,216,130,11,24,90,48,194,
240,105,44,76,34,57,249,228,125,80,38,9,136,29,117,207,139,
168,181,85,137,126,10,126,242,120,247,121,8,100,12,201,171,
38,226,193,180,190,117,177,87,143,242,213,11,44,180,113,93,
106,99,179,68,175,211,164,116,64,148,226,254,172,147
};

byte[] exponent = { 1, 0, 1 };

//Create values to store encrypted symmetric keys.


byte[] encryptedSymmetricKey;
byte[] encryptedSymmetricIV;

//Create a new instance of the RSA class.


RSA rsa = RSA.Create();

//Create a new instance of the RSAParameters structure.


RSAParameters rsaKeyInfo = new RSAParameters();

//Set rsaKeyInfo to the public key values.


rsaKeyInfo.Modulus = modulus;
rsaKeyInfo.Exponent = exponent;

//Import key parameters into rsa.


rsa.ImportParameters(rsaKeyInfo);

//Create a new instance of the default Aes implementation class.


Aes aes = Aes.Create();

//Encrypt the symmetric key and IV.


encryptedSymmetricKey = rsa.Encrypt(aes.Key, RSAEncryptionPadding.Pkcs1);
encryptedSymmetricIV = rsa.Encrypt(aes.IV, RSAEncryptionPadding.Pkcs1);
}
}
Web Services in C#
With Web Services, you can reuse someone else's business logic instead of replicating it
yourself, using just a few lines of code. This technique is similar to what programmers
currently do with libraries of APIs, DLLs or plug-ins. The main difference is that Web
Services can be located remotely on another server. When HTML pages (or the HTML output
generated by ASP.NET web forms) are rendered in a browser for the end user, Web Services
are invoked by other applications. They are pieces of business logic that are hosted
somewhere on the internet and can be accessed by other applications.

Since a web service is cross-platform, there should be some commonly understandable


language for requesting a service and getting a response from the service. Such a standard
common language is XML. That's why Web Services are built on XML-based standards for
exchanging data. As a result, the set of data types Web Services can use is limited to the set of
data types recognized by the XML Schema standard. So you can use simple data types such
as strings and numbers to communicate with a web service and you can't send
proprietary .NET objects such as a FileStream, an Image or an EventLog. This restriction
makes a lot of sense. Since other programming languages have no way to interpret
these .NET objects, even if you could devise a way to send them over the wire, the client
might not be able to interpret them, that would thwart interoperability.

Note 1: Web Services are not limited to the .NET Framework. The standards were defined
before .NET was released and they are exposed, used and supported by vendors other than
Microsoft.

Note 2: Web Services are cross-platform; a service written in one language can be invoked by
an application in some other language. The only requirement for accessing a service is an
internet connection to make the HTTP request.

Note 3: If you need to work with .NET proprietary objects, you can go for .NET remoting. It
is a distributed technology that allows use of .NET objects. But non-.NET clients can't
consume it.
Here's the list of supported data types: -
• Built-in types (The Basics): The built in C# data types such as short, int, long, ushort,
uint, ulong, float, double, decimal, bool, string, char, byte and DateTime.
• Objects: You can use an object of any user defined class. If your class has methods,
these methods will not be transmitted to the client.
• Arrays: Arrays of any supported type (built-in or custom objects). You can also use
an ArrayList (that is simply converted into an array).
• Enumerations: Enums are supported. However, a web service uses the string name of
the enumeration value, not the underlying integer.
• XmlNode: Objects based on System.Xml.XmlNode represent a portion of an XML
document. You can use this to send arbitrary XML.
• DataSet and DataTable : DataSet and DataTable are allowed. But other ADO.NET
data objects, such as DataColumns and DataRows, aren't supported.

Building an XML Web Service


XML serialization converts (serializes) the public fields and properties of an object, and the
parameters and return values of methods, into an XML stream that conforms to a specific
XML Schema definition language (XSD) document. XML serialization results in strongly
typed classes with public properties and fields that are converted to a serial format (in this
case, XML) for storage or transport. Because XML is an open standard, the XML stream can
be processed by any application, as needed, regardless of platform. For example, XML Web
services created using ASP.NET use the XmlSerializer class to create XML streams that pass
data between XML Web service applications throughout the Internet or on intranets.
Conversely, deserialization takes such an XML stream and reconstructs the object.

XML serialization can also be used to serialize objects into XML streams that conform to the
SOAP specification. SOAP is a protocol based on XML, designed specifically to transport
procedure calls using XML. To serialize or deserialize objects, use the XmlSerializer class.
To create the classes to be serialized, use the XML Schema Definition tool.

Web Service Client – WSDL and SOAP


There are various technologies available that support Web Services. There are four prominent
technologies:

XML
An XML Web service is nothing more than a piece of programming code made available to
other programs through the Internet. An XML Web service can be as basic as a piece of code
or an object that publishes data over the Internet using HTTP or another standard protocol.

SOAP
Soap is an acronym for "Simple Object Access Protocol." SOAP is an XML based protocol.
SOAP is used on any system and in any programming language. You can communicate with
different programming languages by utilizing SOAP.
WSDL
Web Services Description Language is the abbreviation for WSDL. WSDL is the standard
format for describing a web service and is widely used. In the development of WSDL, both
Microsoft and IBM worked together. Sharing data in decentralized and distributed systems is
made possible via the WSDL, an XML-based protocol.

UDDI
The "Universal Description, Discovery, and Integration (UDDI)" specification establishes a
standard for publishing and discovering web service information. UDDI registries use the
UDDI standard to provide web service directories. Web services are also linked to Technical
models in the UDDI definition. A UDDI registry user can search for a kind of service using
these patterns, or general groups, instead of knowing the login information for a particular
service.

Web Service with Complex Data Types


To work with complex data, we generally use a dataset. We will create a web service and use
a dataset in the web service application that returns records from a student table. There is a
database "STUDENT" and a database table "student_detail". So, let's create a web service.
Create an ASP.NET Web Service Application and replace the code with the following code.
using System;
using System.Collections.Generic;
using System.Linq; using
System.Web; using
System.Web.Services; using
System.Data.SqlClient; using
System.Data;

namespace WebService2
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment
the following line.
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
string connstring =
"Database=STUDENT;server=.;user=XXXX;password=XXXXXXXX";
DataSet ds;
DataView dv;
SqlDataAdapter da;
[WebMethod(Description= "to show record")]
public DataSet show()
{
da = new SqlDataAdapter("select * from STUDENT_DETAIL", connstring);
ds = new DataSet();
da.Fill(ds);
return ds;
}
}
}
Now we perform some more operations. Now, I am creating a web service application which
can search the records and filter the records in a different way. Again create a Web Service
Application and replace the code with the following code. using System;
using System.Collections.Generic;
using System.Linq; using
System.Web; using
System.Web.Services; using
System.Data.SqlClient; using
System.Data;

namespace WebService2
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment
the following line.
// [System.Web.Script.Services.ScriptService] public
class Service1 : System.Web.Services.WebService {
string connstring =
"Database=STUDENT;server=.;user=XXXX;password=XXXXXXXX";
DataSet ds;
DataView dv;
SqlDataAdapter da;
[WebMethod(Description= "to show record")]
public DataSet show()
{
da = new SqlDataAdapter("select * from STUDENT_DETAIL", connstring);
ds = new DataSet();
da.Fill(ds);
return ds;
}
[WebMethod(Description = "simple filter")]
public DataTable filter(string column)
{
da = new SqlDataAdapter("select * from STUDENT_DETAIL", connstring);
DataSet ds = new DataSet();
da.Fill(ds);
DataView dv = new DataView(ds.Tables[0]);
dv.RowFilter = "f_name like '"+column+"%' "; return
dv.ToTable();
}
[WebMethod(Description = "advance sort")]
public DataTable advancesort(string column, string sort)
{
da = new SqlDataAdapter("select * from STUDENT_DETAIL", connstring);
DataSet ds = new DataSet();
da.Fill(ds);
DataView dv = new DataView(ds.Tables[0]);
dv.Sort = " "+column+" " + ""+sort+"";
return dv.ToTable();
}
[WebMethod(Description = "advancefilter")]
public DataTable advancefilter(string column, string value)
{
da = new SqlDataAdapter("select * from STUDENT_DETAIL", connstring);
DataSet ds = new DataSet();
da.Fill(ds);
DataView dv = new DataView(ds.Tables[0]);
dv.RowFilter = " "+column+" = '" + value + "' "; return
dv.ToTable();
}
[WebMethod(Description="simple sorting")]
public DataTable sort(string column)
{
da = new SqlDataAdapter("select * from STUDENT_DETAIL", connstring);
DataSet ds = new DataSet();
da.Fill(ds);
DataView dv = new DataView(ds.Tables[0]);
dv.Sort = " "+ column +" ";
return dv.ToTable();

}
}
}
Create a web application and consume the service. Now write the following code on
the .aspx.cs page. using System;
using System.Collections.Generic;
using System.Linq; using
System.Web; using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace WebApplication3
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnshowfullrecord_Click(object sender, EventArgs e)
{
localhost.Service1 obj=new localhost.Service1();
DataSet ds = obj.show();
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
protected void btnsort_Click(object sender, EventArgs e)
{
if (txtvalue.Text == "")
{
lblerror.Text = "Plz, Enter Column name";
}
else {
localhost.Service1 obj = new localhost.Service1();
GridView1.DataSource = obj.sort(txtcolumn1.Text);
GridView1.DataBind();
}
}
protected void btnadvancesort_Click(object sender, EventArgs e)
{
if (txtcolumn2.Text == "" || txtascordesc.Text == "")
{
lblerror.Text = "Plz, Fill Both (Column anme and Asc/Desc ";
}
else
{
localhost.Service1 obj = new localhost.Service1();
GridView1.DataSource = obj.advancesort(txtcolumn2.Text, txtascordesc.Text);
GridView1.DataBind();
}
protected void advancefilter_Click(object sender, EventArgs e)
{
localhost.Service1 obj = new localhost.Service1();
GridView1.DataSource = obj.advancefilter(txtcolumnfilter.Text, txtvaluefilter.Text);
GridView1.DataBind();
}
protected void btnfilter_Click(object sender, EventArgs e)
{
if (txtvalue.Text == "")
{
}
else
{
localhost.Service1 obj = new localhost.Service1();
GridView1.DataSource = obj.filter(txtvalue.Text);
GridView1.DataBind();
}
}
}
}

You might also like