Tuesday, December 28, 2010

How to Display icon of a site in Address bar of Browser?

You may have seen for many websites there will be an icon appearing in the addressbar of the browser as in image shown below.

If you wonder how to get this for your site also here is the answer.
  • First you need to make an icon of your choice
  • Add that to your project
  • Use the following code to get this thing done.
Place the code into your <head> tags

<link rel="shortcut icon" href="favicon.ico" />

.ico files are recommended and you can make any image to icon file by using the following website.

Website Which Converts Any Image to "ICON FILE":
http://www.html-kit.com/favicon/

How to Disable Right Click on your Page?

Some times you need to protect your code from viewing in the browsers window by "ViewSource" option in the browser.

this will help you from not displaying some Meta-Tag's information or just the clients requirement.

You can do this by following code in <html> tag as follows

<html onContextmenu = "return false">
 ......
</html>

You can also restrict to some part of the page as follows.


<div onContextmenu = "return false">
 ......
</div>


Note: This option is limited to browser compatibility.

Tuesday, December 21, 2010

Export the Contents of GridView into Excel

Many times you will need to generate reports. Some times the client may ask the data in GridView into an Excel sheet. This is how its done.


First you need to provide a button for exporting and write the following code in the Click Event.

Btn_ExportToExcel.Click()
{
ds = new DataSet();

SqlDataAdapter adp = new SqlDataAdapter(" select * from PhoneBook<tablename or query>",
con);
        adp.Fill(ds);
        grdPhone.DataSource = ds;
        DataTable dt = ds.Tables[0];
        string attachment = "attachment; filename=PhoneBook<ExcelSheet name>.xls";
        Response.ClearContent();
        Response.AddHeader("content-disposition", attachment);
        Response.ContentType = "application/vnd.ms-excel";
        string tab = "";
        foreach (DataColumn dc in dt.Columns)
        {
            Response.Write(tab + dc.ColumnName);
            tab = "\t";
        }
        Response.Write("\n");
        int i;
        foreach (DataRow dr in dt.Rows)
        {
            tab = "";
            for (i = 0; i < dt.Columns.Count; i++)
            {
                Response.Write(tab + dr[i].ToString());
                tab = "\t";
            }
            Response.Write("\n");
        }
        Response.End();



Thats it! This will give you the entire data in GridView to Excel Sheet. You may need to format the excel sheet for further use.

Similarly you can also export the data in PDF also.

Monday, December 20, 2010

How to Get the Row number in RowCommand Event of Gridview?

Has a developer  you need to know the different ways of doing the same thing.

For Example Updating a Row in a Gridview of ASP.Net with in the Gridview.
  • You could do by RowUpdating event of Gridview or
  • Use RowCommand Event.
In any of the methods you need to get the selected row. In  RowUpdating event of Gridview you can get that by simply using the command arguments such as 'e'. Using RowIndex you will get the selected row.

On the other hand what about when we use Row Command Event. Here how its done.

Here we are taking a button which will edit the row. When we press this button it make the controls editable and after when we click on update the selected row should be updated.

to get the Selected Row we Use CommmandArgument of the button as follows.This is .aspx page


<asp:Button ID="btnEdit" runat="server" CausesValidation="false" CommandName="EditRow"
                            Text="Edit" AccessKey="W" AccessControlId="btnEdit" CommandArgument='<%#DataBinder.Eval(Container, "RowIndex")%>' />




So in cs page or code behind page you can get this bu following code

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
               if (e.CommandName == "EditRow")
        {
            try
            {
                int i = int.Parse(e.CommandArgument.ToString());

                .......
                .......
             }
        }
    }

Now you get the SelectedRow !

Thursday, December 16, 2010

Meta Tag For Transition Of The Pages

Meta tags are used for different purposes. Some use them as SEO technique while other use to describe the page.

I came across some other use of them. They can be used to give some transitional effects while displaying the pages just like in Microsoft PowerPoint while displaying the slides.

this is the Tag.

<meta http-equiv="Page-Exit" content="progid:DXImageTransform.Microsoft.GradientWipe(GradientSize=0.75,wipestyle=1,motion=forward,duration=1)" />

Just paste the above code in between <head> tags and see the magic.

I did not test the Browser compatibility yet so please test for yourself before using it.

New Blogger on the web

Hi Guys,

This is Pavan from Hyderabad. I am a new Blogger and i created this Blog for .Net Articles and information.

I Created this blog coz I need to keep track of What I Come across in my Developer Life.

Hope This works.