Advertisements

Friday, June 29, 2012

// // Leave a Comment

Opening a Webpage according to Textbox Value

Hi,

Today I am going to tell you, how to Open a Web Page according to TextBox Value in ASP.NET. You can implement same in Plain HTML Page. This will use a Simple JavaScript Function which we will create according to our need.
Lets Look at the Code. We are using ASP.NET Ajax AutoCompleteExtender for more enhancement in Code (This will only work in ASP.NET).
Code for ASPX Page (HTML Design Part - ASP.NET)

 






If you are using Plain HTML, Just use this code.
 


Now JavaScript Code which is Inserted Directly in Head Section. (JavaScript)





Now code for C# page if you are using AutoComplete Extender.
[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]

public static string[] GetCompletionList(string prefixText, int count, string contextKey)

{

string[] Brands = { "hp", "acer", "dell", "lenovo" };

return (from m in Brands where m.StartsWith(prefixText, StringComparison.CurrentCultureIgnoreCase) select m).Take(count).ToArray();

}
Enjoy...
Read More

Friday, June 22, 2012

// // 1 comment

Export to Excel from DataGridView in ASP.NET

Hi,
We are going to learn how to Export GridView data to Microsoft Excel at Runtime.

We are using: ASP.NET Framework 4.0, Visual Studio 2010, SQL Server 2008, C#, XHTML 4.01

 Code for ASPX Page (Front-End) Adding GridView and Columns:

 <asp:GridView ID="gvPros" runat="server" AutoGenerateColumns="false" Width="664px" Font-Names="Calibri"
                    HeaderStyle-Font-Bold="true" AlternatingRowStyle-BackColor="LightGoldenrodYellow" EmptyDataText="No Records Found. Try again by Changing Filter Options.">
                    <Columns>
                        <asp:TemplateField HeaderText="Party Name">
                            <ItemTemplate>
                                <asp:Label ID="lblPartyName" runat="server" Text='<%#Eval("PartyName")%>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                    <Columns>
                        <asp:TemplateField HeaderText="Mode">
                            <ItemTemplate>
                                <asp:Label ID="lblFreight" runat="server" Text='<%#Eval("Division")%>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                    <Columns>
                        <asp:TemplateField HeaderText="Month">
                            <ItemTemplate>
                                <asp:Label ID="lblMonthName" runat="server" Text='<%#Eval("ProMonth")%>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                    <Columns>
                        <asp:TemplateField HeaderText="Total Box">
                            <ItemTemplate>
                                <asp:Label ID="lblTotalBox" runat="server" Text='<%#Eval("ProPkg")%>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                    <Columns>
                        <asp:TemplateField HeaderText="Actual Weight">
                            <ItemTemplate>
                                <asp:Label ID="lblPartyName" runat="server" Text='<%#Eval("ProActWt")%>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                    <Columns>
                        <asp:TemplateField HeaderText="Charged Wt">
                            <ItemTemplate>
                                <asp:Label ID="lblChWt" runat="server" Text='<%#Eval("ProChWt")%>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                    <Columns>
                        <asp:TemplateField HeaderText="Freight">
                            <ItemTemplate>
                                <asp:Label ID="lblFreight" runat="server" Text='<%#Eval("ProFreight")%>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>

Adding Export Link
 <asp:LinkButton ID="lnkExport" runat="server" Text="Export to Excel" onclick="lnkExport_Click"></asp:LinkButton>

Now Code for ASPX.CS Page (BackEnd):


Namespaces :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Drawing;
using System.IO;
using System.Text;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;

Data Binding and Export LinkButton Click Event:
void GVProsFill()
    {
        string Query = "Select * from Parties,  Prosperity where Parties.PartyID=Prosperity.ProParty";
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConToSEPL"].ConnectionString);
        SqlDataAdapter adp = new SqlDataAdapter(Query, con);
        DataSet ds = new DataSet();
        adp.Fill(ds);
        gvPros.DataSource = ds.Tables[0];
        gvPros.DataBind();
    }
 
//You have to add an another Event for Export to work properly:
public override void VerifyRenderingInServerForm(Control control) 
     { 
         // Can Leave This Blank. 
     }

protected void lnkExport_Click(object sender, EventArgs e)
    {
        Response.ClearContent();
        Response.Buffer = true;
        Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "Prosperity.xls"));
        Response.ContentType = "application/ms-excel";
        StringWriter sw = new StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);
        gvPros.AllowPaging = false;
        GVProsFill();
        gvPros.HeaderRow.Style.Add("background-color", "#FFFFFF");
        for (int a = 0; a < gvPros.HeaderRow.Cells.Count; a++)
        {
            gvPros.HeaderRow.Cells[a].Style.Add("background-color", "#507CD1");
        }
        int j = 1;
        foreach (GridViewRow gvrow in gvPros.Rows)
        {
            gvrow.BackColor = Color.White;
            if (j <= gvPros.Rows.Count)
                {
     if (j % 2 != 0)
      {
       for (int k = 0; k < gvrow.Cells.Count; k++)
         {
        gvrow.Cells[k].Style.Add("background-color", "#EFF3FB");
         }
      }
    }
   j++;
        }
        gvPros.RenderControl(htw);
        Response.Write(sw.ToString());
        Response.End();
    }

I will be waiting to Listen from you....
John Bhatt
Read More

Tuesday, June 12, 2012

// // Leave a Comment

Microsoft Excel 2003 : File Menu and Its Commands-1

Hello Friends,

I am Back with Excel Tutorial Series. Lets Start with File Menu and Its Commands....

1) New (Ctrl+N) : 

As in earlier software we learned, New works same. When clicked New in File menu you will get New option in Task Pane and you have following options to choose:
Blank Workbook
From Existing Workbook….
As I told earlier, MS-Excel’s document is known as Workbook. Choose Blank Workbook to create one.
Shortcut Key for New Blank Workbook is CTRL+N (^N).









2) Open (Ctrl+O) :

This option is used to Open previously saved Workbook for Viewing, Editing, Printing or Analyzing.
Shortcut for this option is CTRL+O.  Here is Open Dialogue Box.

3) Close :

This command is used to close current workbook. You can close your file without exiting from program. 
When clicked Close it prompts you to save workbook if it is not saved yet. 
Shortcut for this option is CTRL+W.

4) Save (Ctrl+S) :

This option saves current active workbook. 
If it is being saved first time it displays Save As Dialogue Box and gives you option to choose location, give name of workbook and Set File Format else it updates current workbook. 
Shortcut for this command is CTRL+S. Here is a Save As Dialogue Box.

5) Save As :

This command displays Save As dialogue box each and every time you click/choose this option. Even your workbook is Already saved, you will get Save As dialogue box to save your file with other name, at other location or with another format/extension. This command is also a very popular and useful command for Excel. 
Shortcut Key for this option is F12.

6) Save As Web Page :

This command saves current workbook as Web Page so that it can be published on the web. You have options to choose which sheet you want to publish, Add interactivity, etc. Whenever clicked this option, save as dialogue box appears with some modification. Such as Change Title and other option.


7) Save Workspace ;


A Document Workspace site is a Microsoft Windows Share Point Services site that is centered around one or more documents. You and your friend can work on same Workbook at same time at Workspace and update the individual work at final stage.
So this is very good feature of MS-Excel that makes work easy and friendly in Networking.

8) File Search : 

This option is used to search Files or File Contents. This is same as File or Folder Search option in Start Menu. But you can search only such documents which are supported by MS-Excel. You have feature to choose location and File Type on Task Pane when this option is chosen.



9) Permissions :


You can create workbook with restrictions only if you have installed Professional version of Microsoft Office 2003.
This feature works on MS-Word, MS-Excel, MS-PowerPoint or MS-Excess only if Information Right Management feature is added to your software.
This feature manages to whom you allow to make change or share your file.

10) Web Page Preview:


This option shows the workbook in browser how it would look like after publishing. If you have created your document for Web Page purpose you can experience the high quality fun of creating web pages. The temporarily converted webpage is stored in temporary folder in .mht and final output file is in .html format.

Remaining Options will be completed soon.

Thanks for Patient. 
Read More

Sunday, June 10, 2012

// // Leave a Comment

Shortcuts in Microsoft Excel 2003

Some Basic and Important Shortcuts.

     Short Key                                          Function
Tab or  Key (Right Arrow)           Move One Cell Right.
Shift + Tab or  (Left Arrow)         Move One Cell Left.
Enter or  Key  (Down Arrow)      Move One Cell down.
Shift + Enter or  (Up Arrow)       Move one Cell up.
Page Up                                          One Screen Up.
Page Down                                     One Screen Down.
Alt + Page Up                                One Screen Left
Alt + Page Down                           One Screen Right
Ctrl + Page Up                               Move Worksheet Left
Ctrl + Page Down                          Move Worksheet Right
Ctrl + End                                      Last Active Cell
Ctrl + Home                                  First Active Cell
Ctrl +    (Right Arrow)              Last Column of Workbook
Ctrl +     (Left Arrow)               First Column of Workbook
Ctrl +     (Down Arrow)            Last Row of Workbook
Ctrl +      (Up Arrow)               First Row of Workbook

How to Close Microsoft Excel  2003.

You can close Microsoft Excel in following ways:
  • Click on Lower Close button located below the Title Bar’s Close button. Doing this will prompt you top save document if it is not saved yet. Then Click on Close Button of Title Bar.
  • Right Click on File Name in Task Bar and choose  Close option. Microsoft Excel will prompt you to save document if it is unsaved.
  • Click on ALT+F4 key directly from Keyboard. Microsoft Excel will prompt you to save document if it is unsaved.

Read More