Thursday, October 11, 2012

Insert and Fetch Image from Database Using .Net

In this Example I will show you how to insert and fetch Image Directly from Database.

Step 1. First We will create Table.




Step 2.
Now code to insert image in Database
SaveImage.aspx

Design.

<form id="form1" runat="server">
    <asp:FileUpload ID="FileUpload1" runat="server" />
    <asp:Button ID="Button1" runat="server"
        Text="Button" onclick="Button1_Click" />
</form>


Code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
public partial class saveimageinbinary : System.Web.UI.Page
{
    SqlConnection conn;
    string s = ConfigurationManager.ConnectionStrings["imageconverter"].ConnectionString.ToString();
    protected void Page_Load(object sender, EventArgs e)
    {
        conn = new SqlConnection(s);
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        StartUpLoad();
    }
    private void StartUpLoad()
    {

        //get the image file that was posted (binary format)

        byte[] theImage = new byte[FileUpload1.PostedFile.ContentLength];
        HttpPostedFile Image = FileUpload1.PostedFile;
        Image.InputStream.Read(theImage, 0, (int)FileUpload1.PostedFile.ContentLength);
        int length = theImage.Length; //get the length of the image
        string fileName = FileUpload1.FileName.ToString(); //get the file name of the posted image
        string type = FileUpload1.PostedFile.ContentType; //get the type of the posted image
        int size = FileUpload1.PostedFile.ContentLength; //get the size in bytes that
        if (FileUpload1.PostedFile != null && FileUpload1.PostedFile.FileName != "")
        {
            //Call the method to execute Insertion of data to the Database
            ExecuteInsert(theImage, fileName, length);
            Response.Write("Save Successfully!");
        }
    }

    private void ExecuteInsert(byte[] Image, string Name, int length)
    {
        
        string sql = "INSERT INTO TblImages (Image, ImageName) VALUES "
       + " (@img,@imgname)";

       // SqlCommand cmd = new SqlCommand(sql,conn);

       // conn.Open();
       //// cmd.ExecuteNonQuery();
       
        try
        {
            conn.Open();
            SqlCommand cmd = new SqlCommand(sql, conn);
            SqlParameter[] param = new SqlParameter[4];

            param[0] = new SqlParameter("@img", SqlDbType.Image, length);

            param[1] = new SqlParameter("@type", SqlDbType.NVarChar, 50);
            param[2] = new SqlParameter("@imgsize", SqlDbType.BigInt, 9999);
            param[3] = new SqlParameter("@imgname", SqlDbType.NVarChar, 50);

            param[0].Value = Image;

            param[1].Value = Type;
            param[2].Value = Size;
            param[3].Value = Name;

            for (int i = 0; i < param.Length; i++)

            {
                cmd.Parameters.Add(param[i]);
            }

            cmd.CommandType = CommandType.Text;

            cmd.ExecuteNonQuery();
        }
        catch (System.Data.SqlClient.SqlException ex)
        {
            string msg = "Insert Error:";
            msg += ex.Message;
            throw new Exception(msg);
        }
        finally
        {
        
            conn.Close();
        }
    }
}

Step 3
Fetch Image from Database.
Here I am using Handler.ashx page to retrieve image.
ShowImage.aspx


Design.


 <div>
 <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true"             onselectedindexchanged="DropDownList1_SelectedIndexChanged">
        </asp:DropDownList><br />
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br />
        <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label><br />
</div>

Code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class showbinaryimage : System.Web.UI.Page
{
    SqlConnection connection;
    string s = ConfigurationManager.ConnectionStrings["imageconverter"].ConnectionString.ToString();
    private void BindFileNames()
    {

        DataTable dt = new DataTable();
      //  SqlConnection connection = new SqlConnection(GetConnectionString());

        try
        {
            connection.Open();
            string sqlStatement = "SELECT * FROM TblImages";
            SqlCommand sqlCmd = new SqlCommand(sqlStatement, connection);
            SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);

            sqlDa.Fill(dt);
            if (dt.Rows.Count > 0)
            {
                DropDownList1.DataSource = dt;
                DropDownList1.DataTextField = "ImageName"; // the items to be displayed in the list items
                DropDownList1.DataValueField = "Id"; // the id of the items displayed
                DropDownList1.DataBind();
            }
        }
        catch (System.Data.SqlClient.SqlException ex)
        {
            string msg = "Fetch Error:";
            msg += ex.Message;
            throw new Exception(msg);
        }
        finally
        {
            connection.Close();
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            BindFileNames();
            connection = new SqlConnection(s);
        }
    }
    public string GetConnectionString()
    {
        //sets the connection string from your web config file "ConnString" is the name of your Connection String
        return System.Configuration.ConfigurationManager.ConnectionStrings["imageconverter"].ConnectionString;
    }
    private void GetImageInfo(string id)
    {
        
        string sql = "SELECT * FROM TblImages WHERE Id = @id";

        SqlCommand cmd = new SqlCommand(sql, connection);
        cmd.Parameters.AddWithValue("@id", id);
        connection.Open();

        SqlDataReader reader = cmd.ExecuteReader();
        reader.Read();

        //Get Image Information
        Label1.Text = reader["ImageName"].ToString();
        reader.Close();
        connection.Close();
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (DropDownList1.SelectedIndex > 0)
        {
            //Set the ImageUrl to the path of the handler with the querystring value
            Image1.ImageUrl = "Handler.ashx?id=" + DropDownList1.SelectedItem.Value;
            //call the method to get the image information and display it in Label Control
            GetImageInfo(DropDownList1.SelectedItem.Value);
        }
    }
   
}


Handler.ashx



<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using System.IO;
using System.Collections.Specialized;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
public class Handler : IHttpHandler {

    public string GetConnectionString()
    {
        //sets the connection string from your web config file "ConnString" is the name of your Connection String
        return System.Configuration.ConfigurationManager.ConnectionStrings["imageconverter"].ConnectionString;
    }
     public void ProcessRequest(HttpContext context)
    {
        string id = context.Request.QueryString["id"]; //get the querystring value that was pass on the ImageURL (see GridView MarkUp in Page1.aspx)

        if (id != null)
        {
           
            MemoryStream memoryStream = new MemoryStream();
            SqlConnection connection = new SqlConnection(GetConnectionString());
            string sql = "SELECT * FROM TblImages WHERE Id = @id";
       
            SqlCommand cmd = new SqlCommand(sql, connection);
            cmd.Parameters.AddWithValue("@id", id);
            connection.Open();

            SqlDataReader reader = cmd.ExecuteReader();
            reader.Read();

            //Get Image Data
            byte[] file = (byte[])reader["Image"];

            reader.Close();
            connection.Close();
            memoryStream.Write(file, 0, file.Length);
            context.Response.Buffer = true;
            context.Response.BinaryWrite(file);
            memoryStream.Dispose();

        }
    }

    public bool IsReusable {
        get {
            return false;
        }
    }
}

Sunday, September 2, 2012

Color Particular Cell of Gridview

In this Example i will use onRowDataBound property of Gridview to color particular cell.

Just we have call a function on "onRowDataBound" property 
Ex: onRowDataBound="Grid_rowColor"

.aspx Page
 
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="id"  OnRowDataBound="Grid_rowColor">
    <Columns>
    <asp:BoundField DataField="name" HeaderText="name" SortExpression="name" ReadOnly="true" />
    <asp:BoundField DataField="number" HeaderText="number" ReadOnly="true"  SortExpression="number" />

    </Columns>
</asp:GridView>

 <asp:SqlDataSource ID="SqlDataSource1" runat="server"
 ConnectionString="<%$ ConnectionStrings:testchatConnectionString %>"
  SelectCommand="SELECT [name], [number], [id] FROM [testdemo]">
  </asp:SqlDataSource>

.cs page
 public void Grid_rowColor(object sender, GridViewRowEventArgs e)
    {
    if(e.Row.RowType==DataControlRowType.DataRow)
    {
        int value1= Convert.ToInt32(e.Row.Cells[1].Text.ToString());
        if (value1 > 2 && value1 < 30)
        {
            for (int i = 0; i < e.Row.Cells.Count; i++)
            {
                e.Row.Cells[i].BackColor = System.Drawing.Color.Green;
            }
        }
        else if (value1 >= 30 && value1 <= 50)
        {
            for (int i = 0; i < e.Row.Cells.Count; i++)
            {
                e.Row.Cells[i].BackColor = System.Drawing.Color.Gray;
            }

        }
        else
        {
            for (int i = 0; i < e.Row.Cells.Count; i++)
            {
                e.Row.Cells[i].BackColor = System.Drawing.Color.Yellow;
            }
        }
      }
    }

Thursday, August 30, 2012

LINQ to Object Examples

LINQ: Language Integrated Query


you’ll need to persist objects to a database, query the database and load the results back into objects. The problem is that in
most cases, at least with relational databases, there is a gap between your programming language and the database. Good attempts have been made to provide object-oriented databases, which would be closer to object-oriented platforms and imperative programming languages like C# and VB.NET. However, after all these years, relational databases are still pervasive and you still have to struggle with data-access and persistence in all of your programs.The original motivation behind LINQ was to address the impedance mismatch between programming languages and databases. With LINQ, Microsoft’s intention was to provide a solution for the problem of  object-relational mapping, as well as simplify the interaction between objects and data sources. 

LINQ eventually evolved into a general-purpose language-integrated querying toolset. This toolset can be used to
access data coming from in-memory objects (LINQ to Objects), databases (LINQ to SQL), XML documents (LINQ to XML), a file-system, or from any other source.

Examples


 Response.Write("<h2>LINQ to Object</h2>");

        int[] numbers = { 5,6,7,8,3,4,9,1,2,0 };

        var no= from n in numbers
                    group n by n % 2 into g 
                    select new { Reminder=g.Key ,Number=g   };
        foreach (var g in no)
        {
            string s = string.Format("<br/>no of remainder of {0} when divided by 2:", g.Reminder);
            Response.Write(s);
            
            foreach (var n in g.Number)
            {
                Response.Write("<br/>"+n);
            }
        }
        /*
     OUTPUT
      no of remainder of 1 when divided by 2:
     5
     7
     3
     9
     1
      no of remainder of 0 when divided by 2:
     6
     8
     4
     2
     0
        */
        // for word lenth
        Response.Write("<h3>find length of word</h3>");
  string[] word = { "ABCD","EFG","HIJKL","MN","OPQRST","UVWXYZ"};

        var len = from words in word

                 // where words.Length <= 5
                 orderby words.Length ascending
                  select words;
        foreach (var leng in len)
        {
            Response.Write("<br/>" + leng + " >>Length :" + leng.Length);
        }
              
          /*
           OUTPUT
        find length of word
        MN >>Length :2
        EFG >>Length :3
        ABCD >>Length :4
        HIJKL >>Length :5
        OPQRST >>Length :6
        UVWXYZ >>Length :6
           */
                      
        //find even no

        Response.Write("<h3>find even number</h3>");

        int[] number = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15 };

        var ev = from even in number
                 where even % 2 == 0
                 orderby even descending
                 select even;
        Response.Write("Even Number<br/>");
        foreach (var evn in ev)
        {
            Response.Write(evn+"<br/>");
        }

        /*
         OUTPUT
      find even number
      Even Number
    12
    10
    8
    6
    4
    2
       */    

Friday, August 17, 2012

Split and Merge File Example in asp.net

In this example i am showing how to split the file size into more than one file.
(Example: suppose file size is of 200byte and i want to split this file into 2 part 100byte each and save them)

in .aspx page
 <asp:FileUpload ID="FileUpload1" runat="server" />
 <asp:Button ID="btnupload" runat="server" Text="find Byte"
          onclick="btnupload_Click" />
 </p>
 <p>
  No to split :
 <asp:TextBox ID="txtsayno" runat="server"></asp:TextBox>
 </p>
 <p>
 <asp:Button ID="btnsplit" runat="server" onclick="btnsplit_Click" Text="Split" />
 </p>
 
 
in .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.IO;
public partial class _Default : System.Web.UI.Page
{
    FileInfo info;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnupload_Click(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile && FileUpload1.FileContent.Length > 0)
        { FileUpload1.PostedFile.SaveAs(

Server.MapPath("file/"+FileUpload1.FileName));
         info=new FileInfo(Server.MapPath("file/"+FileUpload1.FileName));
         Session["filename"] = "file/" + FileUpload1.FileName;
            long fileinByte=info.Length;
            Response.Write(fileinByte);
        }
    }
    protected void btnsplit_Click(object sender, EventArgs e)
    {
        flename = new string[100];
        string file = Server.MapPath(Session["filename"].ToString());
        info = new FileInfo(file);

        FileStream fs = new FileStream(file,FileMode.Open,FileAccess.Read);
       int no=Convert.ToInt32(txtsayno.Text);
        int size=Convert.ToInt32(info.Length / no);
        for (int i=0;i<no;i++)
        {
         
        string basename = Path.GetFileNameWithoutExtension(file);
        string ex = Path.GetExtension(file);
        Session["extension"] = ex;
        FileStream outputFile = new FileStream(Path.GetDirectoryName(file) + "\\" + basename + "." + i.ToString().PadLeft(5, Convert.ToChar("0")) + ex + ".tmp", FileMode.Create, FileAccess.Write);
       flename[i] = basename + "." + i.ToString().PadLeft(5, Convert.ToChar("0")) + ex + ".tmp";
       string mergeFolder = Path.GetDirectoryName(file);
                    int bytesRead = 0;
                    byte[] buffer = new byte[size];
                    if ((bytesRead = fs.Read(buffer, 0, size)) > 0)
                    {
                        outputFile.Write(buffer, 0, bytesRead);
                    }
                    outputFile.Close();
                }
                fs.Close();             
        }

    }

To view Merge Example Click: Merge File

Thursday, August 2, 2012

Client Callbacks Example in Asp.net

Client callbacks : Rather than posting back the entire page, your custom control can send a request to the server to get just the additional information it needs.

Example:                                                        On Click of Button show Alert box with text value.

 in .aspx page                                                             <script type="text/javascript">
        function ss() {
            var va = document.forms[0].Text1.value;
            UseCallback(va, "");
      
    
        }
        function show(Text1, context) {
            alert(Text1);
      
        }
    </script> 
      <asp:Panel ID="Panel2" runat="server">
      <input id="Text1" type="text" runat="server" />
      <input id="Button1" type="button" value="button" onclick="ss()"/>
        </asp:Panel>

   in .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.SqlClient;
using System.Data;
  
 public partial class _Default: System.Web.UI.Page, System.Web.UI.ICallbackEventHandler
{
  protected void Page_Load(object sender, EventArgs e)
    {
        string cref = Page.ClientScript.GetCallbackEventReference(this, "arg", "show", "context");
        string cscript = "function UseCallback(arg,context)" +
            "{" + cref + ";" + "}";
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "UseCallback", cscript, true);
    } 
  public string GetCallbackResult()
    {
        return aa;
    }
    public void RaiseCallbackEvent(string eventArgument)
    {
        aa = eventArgument;
    } 
}
OutPut
 

Saturday, July 14, 2012

Built and Play Piano using Asp.net

In this blog I am showing the example of Making piano.
"Built and play piano using keyboard and mouse"


We can play piano only in client side. On server side this code will not be helpful.
Because i am using "winmm.dll" file for making sound which is located in client computer.


The script will check the keypress event by knowing their ASCII value.
in .aspx

<head runat="server">
    <title></title>
    <script type="text/javascript">


        document.onkeyup = KeyCheck;


        function KeyCheck(e) {
            var KeyID = (window.event) ? event.keyCode : e.keyCode;
            {
                __doPostBack('__Page', KeyID);
                
            }
        }


    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div style="height: 200px; vertical-align: top; background-color:Yellow;" align="center">
        <table>
            <tr>
                <td valign="top"  style="width:41px">
                    <asp:Button ID="Button1" runat="server" Text="A" BackColor="White" BorderColor="Black"
                        BorderStyle="Solid" BorderWidth="1px" Height="192px" Width="41px" />
                    &nbsp;
                </td>
                <td valign="top" style="width:41px">
                    <asp:Button ID="Button2" runat="server" Text="S" BackColor="Black" BorderColor="white"
                        BorderStyle="Solid" BorderWidth="1px" Height="139px" Style="margin-bottom: 0px"
                        ForeColor="White" Width="41px" />&nbsp;
                </td>
                <td valign="top"  style="width:41px">
                    <asp:Button ID="Button3" runat="server" Text="D" BackColor="White" BorderColor="Black"
                        BorderStyle="Solid" BorderWidth="1px" Height="192px" Width="41px" />
                    &nbsp;
                </td>
                <td valign="top"  style="width:41px">
                    <asp:Button ID="Button4" runat="server" Text="F" BackColor="Black" BorderColor="white"
                        BorderStyle="Solid" BorderWidth="1px" Height="139px" Style="margin-bottom: 0px"
                        ForeColor="White" Width="41px" />&nbsp;
                </td>
                <td valign="top"  style="width:41px">
                    <asp:Button ID="Button5" runat="server" Text="G" BackColor="White" BorderColor="Black"
                        BorderStyle="Solid" BorderWidth="1px" Height="192px" Width="41px" />
                    &nbsp;
                </td>
                <td valign="top"  style="width:41px">
                    <asp:Button ID="Button6" runat="server" Text="H" BackColor="Black" BorderColor="white"
                        BorderStyle="Solid" BorderWidth="1px" Height="139px" Style="margin-bottom: 0px"
                        ForeColor="White" Width="41px" />&nbsp;
                </td>
                <td valign="top"  style="width:41px">
                    <asp:Button ID="Button7" runat="server" Text="J" BackColor="White" BorderColor="Black"
                        BorderStyle="Solid" BorderWidth="1px" Height="192px" Width="41px" />
                    &nbsp;
                </td>
                 <td valign="top"  style="width:41px">
                    <asp:Button ID="Button8" runat="server" Text="K" BackColor="Black" BorderColor="white"
                        BorderStyle="Solid" BorderWidth="1px" Height="139px" Style="margin-bottom: 0px"
                        ForeColor="White" Width="41px" />&nbsp;
                </td>
                <td valign="top"  style="width:41px">
                    <asp:Button ID="Button9" runat="server" Text="L" BackColor="White" BorderColor="Black"
                        BorderStyle="Solid" BorderWidth="1px" Height="192px" Width="41px" />
                    &nbsp;
                </td>
                 <td valign="top"  style="width:41px">
                    <asp:Button ID="Button10" runat="server" Text=";" BackColor="Black" BorderColor="white"
                        BorderStyle="Solid" BorderWidth="1px" Height="139px" Style="margin-bottom: 0px"
                        ForeColor="White" Width="41px" />&nbsp;
                </td>
                <td valign="top"  style="width:41px">
                    <asp:Button ID="Button11" runat="server" Text="'" BackColor="White" BorderColor="Black"
                        BorderStyle="Solid" BorderWidth="1px" Height="192px" Width="41px" />
                    &nbsp;
                </td>
            </tr>
        </table>
    </div>
    <div style=" vertical-align: top;" align="center">
        <table>
            <tr>
                <td valign="top"  style="width:41px" align="center">
                    <asp:Image ID="Image1" runat="server" Width="20px" Height="20px"/> 
                  
                </td>
                <td valign="top" style="width:41px"  align="center">
                 <asp:Image ID="Image2" runat="server" Width="20px" Height="20px"/> 
                </td>
                <td valign="top"  style="width:41px"  align="center">
                   <asp:Image ID="Image3" runat="server" Width="20px" Height="20px" /> 
                </td>
                <td valign="top"  style="width:41px"  align="center">
                    <asp:Image ID="Image4" runat="server" Width="20px" Height="20px"/> 
                </td>
                <td valign="top"  style="width:41px"  align="center">
                  <asp:Image ID="Image5" runat="server" Width="20px" Height="20px"/> 
                </td>
                <td valign="top"  style="width:41px"  align="center">
                   <asp:Image ID="Image6" runat="server" Width="20px" Height="20px"/> 
                </td>
                <td valign="top"  style="width:41px"  align="center">
                  <asp:Image ID="Image7" runat="server" Width="20px" Height="20px"/> 
                </td>
                 <td valign="top"  style="width:41px"  align="center">
                  <asp:Image ID="Image8" runat="server" Width="20px" Height="20px"/> 
                </td>
                 <td valign="top"  style="width:41px"  align="center">
                  <asp:Image ID="Image9" runat="server" Width="20px" Height="20px"/> 
                </td>
                 <td valign="top"  style="width:41px"  align="center">
                  <asp:Image ID="Image10" runat="server" Width="20px" Height="20px"/> 
                </td>
                 <td valign="top"  style="width:41px"  align="center">
                  <asp:Image ID="Image11" runat="server" Width="20px" Height="20px"/> 
                </td>
            </tr>
        </table>
    </div>


    <%--<div style=" vertical-align: top;">
       
                    <asp:Image ID="Image12" runat="server" Width="20px" Height="20px" ImageUrl="~/up_arrow.png" style="padding-left:420px"/> 
                  
              
    </div>--%>
    <div align="center">
       <font size="5px" style="font-family:Garamond;" color="red"> Press the no given on piano, to listen sound.</font>
    </div>
    </form>
</body>

Now Code


in .vb page



Imports System.Runtime.InteropServices
Imports Microsoft.VisualBasic.Devices
Imports Microsoft.VisualBasic




Partial Class piano1
    Inherits System.Web.UI.Page
    <DllImport("winmm.dll", EntryPoint:="mciSendStringA")> _
    Private Shared Function mciSendString(ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer
    End Function
    Dim computer As New Computer
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        computer.Audio.Stop()
        visi()
        borderwid()
        Page.ClientScript.GetPostBackEventReference(Me, "")
        Dim eventArgs As String = Request("__EVENTARGUMENT")
        If eventArgs <> "" Then
            If eventArgs = "65" Then


                playsound1()


            ElseIf eventArgs = "83" Then
                playsound2()


            ElseIf eventArgs = "68" Then
                playsound3()
            ElseIf eventArgs = "70" Then
                playsound4()
            ElseIf eventArgs = "71" Then
                playsound5()
            ElseIf eventArgs = "72" Then
                playsound6()
            ElseIf eventArgs = "74" Then
                playsound7()
            ElseIf eventArgs = "75" Then
                playsound8()
            ElseIf eventArgs = "76" Then
                playsound9()
            ElseIf eventArgs = "59" Or eventArgs = "186" Then
                playsound10()
            ElseIf eventArgs = "222" Then
                playsound11()
            End If
        End If


    End Sub
    Public Sub visi()
        Image1.Visible = False
        Image2.Visible = False
        Image3.Visible = False
        Image4.Visible = False
        Image5.Visible = False
        Image6.Visible = False
        Image7.Visible = False
        Image8.Visible = False
        Image9.Visible = False
        Image10.Visible = False
        Image11.Visible = False
    End Sub
    Public Sub borderwid()


        Button1.BorderWidth = "1"
        Button2.BorderWidth = "1"
        Button3.BorderWidth = "1"
        Button4.BorderWidth = "1"
        Button5.BorderWidth = "1"
        Button6.BorderWidth = "1"
        Button7.BorderWidth = "1"
        Button8.BorderWidth = "1"
        Button9.BorderWidth = "1"
        Button10.BorderWidth = "1"
        Button11.BorderWidth = "1"
    End Sub
    Public Sub playsound1()
        computer.Audio.Play(Server.MapPath("piano/s1.wav"), AudioPlayMode.Background)
        Image1.Visible = True
        Image1.ImageUrl = "~/image/up_arrow.png"
        Button1.BorderWidth = "3"
    End Sub
    Public Sub playsound2()
        computer.Audio.Play(Server.MapPath("piano/s2.wav"), AudioPlayMode.Background)
        Image2.Visible = True
        Image2.ImageUrl = "~/image/up_arrow.png"
        Button2.BorderWidth = "3"
    End Sub
    Public Sub playsound3()
        Image3.Visible = True
        Image3.ImageUrl = "~/image/up_arrow.png"
        computer.Audio.Play(Server.MapPath("piano/s3.wav"), AudioPlayMode.Background)
        Button3.BorderWidth = "3"
    End Sub
    Public Sub playsound4()
        Image4.Visible = True
        Image4.ImageUrl = "~/image/up_arrow.png"
        computer.Audio.Play(Server.MapPath("piano/s4.wav"), AudioPlayMode.Background)
        Button4.BorderWidth = "3"
    End Sub
    Public Sub playsound5()
        Image5.Visible = True
        Image5.ImageUrl = "~/image/up_arrow.png"
        computer.Audio.Play(Server.MapPath("piano/s5.wav"), AudioPlayMode.Background)
        Button5.BorderWidth = "3"
    End Sub
    Public Sub playsound6()
        Image6.Visible = True
        Image6.ImageUrl = "~/image/up_arrow.png"
        computer.Audio.Play(Server.MapPath("piano/s6.wav"), AudioPlayMode.Background)
        Button6.BorderWidth = "3"
    End Sub
    Public Sub playsound7()
        Image7.Visible = True
        Image7.ImageUrl = "~/image/up_arrow.png"
        computer.Audio.Play(Server.MapPath("piano/s7.wav"), AudioPlayMode.Background)
        Button7.BorderWidth = "3"
    End Sub


    Public Sub playsound8()
        Image8.Visible = True
        Image8.ImageUrl = "~/image/up_arrow.png"
        computer.Audio.Play(Server.MapPath("piano/s8.wav"), AudioPlayMode.Background)
        Button8.BorderWidth = "3"
    End Sub


    Public Sub playsound9()


        Image9.Visible = True
        Image9.ImageUrl = "~/image/up_arrow.png"
        computer.Audio.Play(Server.MapPath("piano/s9.wav"), AudioPlayMode.Background)
        Button9.BorderWidth = "3"
    End Sub
    Public Sub playsound10()
        Image10.Visible = True
        Image10.ImageUrl = "~/image/up_arrow.png"
        computer.Audio.Play(Server.MapPath("piano/s10.wav"), AudioPlayMode.Background)
        Button10.BorderWidth = "3"
    End Sub
    Public Sub playsound11()
        Image11.Visible = True
        Image11.ImageUrl = "~/image/up_arrow.png"
        computer.Audio.Play(Server.MapPath("piano/s11.wav"), AudioPlayMode.Background)
        Button11.BorderWidth = "3"
    End Sub




    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        visi()
        borderwid()
         playsound1()
    End Sub


    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
        visi()
        borderwid()
        playsound2()
    End Sub


    Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
        visi()
        borderwid()
        playsound3()
    End Sub


    Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click
        visi()
        borderwid()
        playsound4()
    End Sub


    Protected Sub Button5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button5.Click
        visi()
        borderwid()
        playsound5()
    End Sub


    Protected Sub Button6_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button6.Click
        visi()
        borderwid()
        playsound6()
    End Sub


    Protected Sub Button8_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button8.Click
        visi()
        borderwid()
        playsound8()
    End Sub


    Protected Sub Button9_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button9.Click
        visi()
        borderwid()
        playsound9()
    End Sub


    Protected Sub Button10_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button10.Click
        visi()
        borderwid()
        playsound10()
    End Sub


    Protected Sub Button11_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button11.Click
        visi()
        borderwid()
        playsound11()
    End Sub


    Protected Sub Button7_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button7.Click
        visi()
        borderwid()
        playsound7()
    End Sub
End Class

Enjoy Piano