Wednesday, April 3, 2013

hide templatefield column on runtime in gridview

To Hide templatefield column on runtime in gridview:

go to the aspx page of the gridview in the gridview properties search for OnRowCreated event. if not found add that event to the grid.

Example:

<asp:GridView ID="CrowdRatingGrid" runat="server" AutoGenerateColumns="false" OnRowCreated="CrowdRatingGrid_RowCreated" >
...
<asp:TemplateField>
.....
  </asp:TemplateField>
....
   </asp:GridView>

after adding this go to the code behind page and add this method CrowdRatingGrid_RowCreated to handle on row created event.


protected void CrowdRatingGrid_RowCreated(object sender, GridViewRowEventArgs e)
    {...

...

}


Now suppose we have 3 column in our grid and we want to hide the 2nd column then do this:


 protected void CrowdRatingGrid_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[1].Visible = false;
        }
        else if (e.Row.RowType == DataControlRowType.Header)
        {
            e.Row.Cells[1].Visible = false;
        }
    }

This will hide the 2nd column of the gridview control in asp.net

Protected by Copyscape Duplicate Content Detection Tool

how to read a csv file to return a string in asp.net

To read a CSV file to  return a string in asp.net :

Below is the function i have created which reads the csv file and copies it to the application temp folder then converts it to text file and then finally returns the string.

Public string CSVTOSTR(string sourcefilepath)
{

       string readContents;
        FileInfo file = new FileInfo(sourcefilepath);
        string newPath = s + file.Name;
        File.Copy(sourcefilepath, newPath, true);
        System.IO.FileInfo FileInfor = new System.IO.FileInfo(newPath);
        FileInfor.MoveTo(System.IO.Path.ChangeExtension(FileInfor.FullName, ".txt"));

        using (StreamReader streamReader = new StreamReader(FileInfor .FullName, Encoding.UTF8))
        {
            readContents = streamReader.ReadToEnd();
        }

        return readContents;
}



Tuesday, April 2, 2013

difference between WCF and web services


web service
It is an web application  where there is no user interface, just we write the method with implementations which is then consumed by other applications.


windows communication foundation
Its has all the features of a web services other than this it has lot many other advantages.
WCF was introduced with .net 3.0 framework with a view of creating service oriented architectures.

WCF web service
WCF service can be invoked from HTTP,TCP,MSMQ,Named Pipes Web service can be invoked only by HTTP
it can be hosted in the IIS, Self Hosting and WAS(Windows Activation service) It can be only hosted in IIS
Its Supports various type of bindings like http or tcp etc It supports SOAP 
Its is flexible as whenever we make a new version of the service just we to expose a new endpoint web service is not flexible
It uses datacontractserializer which is better in performance than web service it uses XMLserializer
File extension of the WCF is .svc File extension on Web service is .asmx
Supports Security, Reliable messaging, Transaction, Interoperability  Supports Security
service contract, data contract, message contract,operation contract are used in service Here web method and web service are used
Fault contract handles exception whereas in web service exception are given back to client
Protected by Copyscape Duplicate Content Detection Tool

Monday, April 1, 2013

Features of .net framework 4.0


Features of .net framework 4.0 ?

a. We can enable and disable viewstate.

b. Output cache extensibility which means we can use hard drives or any other memory resources to save
the cache data.

c. we can compress the session state values.

d. Response.Redirectpermanent new keyword to permanently redirect to a page.

e. New Keywords introduced in code behind for meta keywords and meta description.
    example : page.metadescription = "Welcome to my website. we provide services for web designing"
                        page.metakeywords = "web designing, professional web designers "

f. Routing in Asp.net 4.0. It helps us to provide a more meaningful URLs.
   http://www.xyz.com/shop.aspx?countryid=91&branchid=6
   using routing we can change it to
   http://www.xyz.com/shop/country/branch

e. Some of the sections from the webconfig file has been moved to the machine config file, which makes our web config file more cleaner and easy to manage.

f. new keyword enviroment.is64bitoperatingsystem introduced to check whether the operating system is a 64 bit or not.

g. Side by side execution : This helps us to run applications simultaneously which are based on different .net frameworks.
 example : one application is on .net 3.5 and other is on .net 4.0 both can run simultaneously.
Protected by Copyscape Duplicate Content Detection Tool

Triggers in Sql Server

Triggers are activated whenever  Insert update delete activity is performed on any table.

Example : Suppose we want to log information about a user who is updating the table and also time of it when the table is being updated. This type of information we can log with the help of triggers.

Two types of triggers :
1. After(For) Triggers
2. Instead of Triggers


Types of Triggers:

1.After trigger :

After trigger gets activated when all the activity on the table has been performed. Lets take an example to view this type of trigger.

first i will create a table and insert some records into it






















Now we will create trigger on emp table for insert operation. So whenever any insert operation is performed on table this trigger will get executed.

So, In this trigger whatever new name is inserted in emp table im inserting that new name into other table called capturedata table.
Along with the new name im also inserting current date in the capturedata table.












We will now insert record in emp table and check whether any record has been logged in capturedata table or not.































2.  Instead of trigger :

Instead of trigger is used when we want to manipulate each data which getting inserted , deleted or updated. Lets take a example to explain this:

suppose we want to delete all records from table except for chetan. Hence in instead of trigger we will write a condition where we will check if name is equal to chetan. if the name is chetan we will not delete that record and will raise a error for that " this record cannot be deleted" or if the name is other than chetan we will delete that record.

we will keep the emp table as it is and will now write  Instead of trigger on delete.

below picture shows how to create a Instead of trigger: