Displaying music and image from file

// Put code into body of page


 <div id="wrapper" class=" mar1">
        <div id="wrapper_inner">
       <!-- Crumb Section -->
              <div id="crumb">
                <%--<a href="#">Home</a> <a class="active" href="#">Club Blog</a>--%>
            </div>
           <!-- Banner  --> 
            <div id="bannerinner">
               
                <asp:Image id="imgBanner" Width="920px" Height="115px" runat="server" ImageUrl="" ></asp:image>
            </div>
          <!--Content Sec -->
               <div id="content_sec">
            <!-- Inner Left Col -->
                <div class="leftcol">
                <div class="right-btn">
                 <asp:Button ID="btnBook" CssClass="artist"
                        ValidationGroup="send" BackColor="#FF00C6" Text="Book this Artist"
                                runat="server"  Visible="false"  onclick="btnBook_Click"  />
                </div>
                   <div class="left" > <h2 class="colr">
                        <asp:Label ID="lblTitle" runat="server"  ></asp:Label> </h2>

                       
                        </div>
                    <div class="blogsec">
                        <ul>
                            <li>
                                <h4>
                                    <asp:Label ID="lblSubtitle" runat="server"  ></asp:Label></h4>
                               
                                <div  style="width:100%; overflow:hidden;">
                                    <div class="postedb">
                                        <p class="posted">
                                            Posted by <asp:Label ID="lblPostedBy" Font-Bold="true" runat="server"  ></asp:Label>  on  <asp:Label ID="lblDate" runat="server"  ></asp:Label></p>
                                      
                                    </div>
                                    <p class="txt">
                                    <asp:Literal ID="Literal1" runat="server"></asp:Literal>
                                        
                                    </p>
                                   
                                </div>
                                <div class="clear"></div>
                                <div runat="server" id="divMusic" visible="false">
                                <asp:Literal ID="LiteralMusic" runat="server"></asp:Literal>
                              

    
    </div>

       
  
                            </li>
                        </ul>
                    </div>
                <!-- Blog Reply -->
                    
                   <!--Paginaiton -->
                    
                </div>

             <!--Right Section-->
                <div class="rightcol">
                <!-- Search Blog-->
                        
                    <div class="box">
                        <h4 class="colr">
                           <asp:Label ID="LblRtop"  runat="server"  ></asp:Label></h4>
                        <ul>
                          
                            <asp:DataList ID="dtlRToplist" RepeatDirection="Vertical"
                    runat="server" 
                     >
                <ItemTemplate>
               
                <li> <a href='<%#"Posting.aspx?id="+ Eval("ListPosingId") %>'> <span>&nbsp;</span><asp:Label ID="lblPostedBy" Text='<%#Eval("title") %>' runat="server"  ></asp:Label></a></li>
                </ItemTemplate>
                </asp:DataList>
                        </ul>
                    </div>
                    <div id="divRbottom"  class="box" visible="false" runat="server" >
                        <h4 class="colr">
                            <asp:Label ID="LblRBottom" runat="server" Visible="false" ></asp:Label>
                        </h4>
                        <ul>
                            <asp:DataList ID="DtlRbottom"  RepeatDirection="Vertical"
                    runat="server"   Visible="false"
                     >
                <ItemTemplate>
               
                <li> <a href='<%#"Posting.aspx?id="+ Eval("ListPosingId") %>'> <span>&nbsp;</span><asp:Label ID="lblPostedBy" Text='<%#Eval("title") %>'  runat="server"  ></asp:Label></a></li>
                </ItemTemplate>
                </asp:DataList>
                        </ul>
                    </div>
                </div>
                <div class="clear">
                </div>
            </div>
            <div class="clear">
            </div>
        </div>
        <div class="clear">
        </div>
    </div>


//Now write code in code behind



 protected void bindata()
    {
       
        lstDetail = context.fnSelectblogdetail(PostId).ToList();
        if (lstDetail[0].PostingType == "Artist")
        {
            btnBook.Visible = true;
            if (!string.IsNullOrEmpty(lstDetail[0].Artistmusic))
            {
                divMusic.Visible = true;
                string musicurl=Convert.ToString(lstDetail[0].Artistmusic);


                strbuild.Append("<object type='application/x-shockwave-flash'  id='dewplayer-vol' data='http://localhost:2471/keeton/dewplayer-vol.swf?mp3=http://localhost:2471/keeton/ArtistMusic/" + musicurl + "&autostart=1' height='30px' width='300px'  >");
                strbuild.Append("<param name='wmode'  value='transparent' /><param  name='movie' start='true' value='http://localhost:2471/keeton/dewplayer-vol.swf?mp3=http://localhost:2471/keeton/ArtistMusic/" + musicurl + "&autostart=1' /></object>");

                LiteralMusic.Text = strbuild.ToString();

            }

           
        }
        imgBanner.ImageUrl = "~/ListPostingImage/" + lstDetail[0].MainImage;
        lblTitle.Text = lstDetail[0].Title;
        lblDate.Text =lstDetail[0].Date.ToString("MMM dd yyyy");
        lblSubtitle.Text = lstDetail[0].Subtiltle;
        lblPostedBy.Text = lstDetail[0].PostedBy;

        Literal1.Text = Server.HtmlDecode(lstDetail[0].Body).Replace("../ListPostingImage/","/keeton/ListPostingImage/");

        //StringBuilder strb = new StringBuilder();
        //strb.Append(str);
        //strb.Append("<br /><h1> deepak</h1>");
        //Literal1.Text = strb.ToString();
              


    }

Uploading image in folder Entity frame work

protected void btnSave_Click(object sender, EventArgs e)
    {
        KeetonModel.KeetonEntities context = new KeetonModel.KeetonEntities();
        if (!Page.IsValid)
            return;
        try
        {

            tblListPosition tblpos;
            if (listPostid > 0)
            {
                tblpos = context.tblListPositions.Where(c => c.ListPosingId == listPostid).FirstOrDefault();
                if (tblpos == null)
                {
                    tblpos = new tblListPosition();
                    context.AddTotblListPositions(tblpos);
                }
            }
            else
            {
                tblpos = new tblListPosition();
                context.AddTotblListPositions(tblpos);
                tblpos.ImageUrl = "";
                tblpos.MainImage = "";
                tblpos.BannerImage = "";
                tblpos.ThumnilImage = "";

            }
            tblpos.Date = Convert.ToDateTime(txtDate.Text);
            tblpos.PostingType = ddlPostType.SelectedValue;
            if (ddlPostType.SelectedValue != "Artist")
            {
                tblpos.ArtistType = null;
            }
            else
                tblpos.ArtistType = ddlArtistType.SelectedValue;

            tblpos.Title = txtTitle.Text;
            tblpos.Subtiltle = txtSustitle.Text;
            tblpos.Body = elm2.InnerHtml;
            tblpos.PostedBy = txtPostedBy.Text;
            tblpos.PublishPosting = ChkPublishPosting.Checked;
            tblpos.BannerStatus = ChkBanner.Checked;
            context.SaveChanges();

            string fileName = "";
            string fileNameBig = "";

            string fileMainName = "";
            string fileMainbig = "";
          
            string fileMusicName = "";

            if (fuMusic.HasFile)
            {

                string Apath = Server.MapPath("~/ArtistMusic");
                if (!Directory.Exists(Apath))
                    Directory.CreateDirectory(Apath);

                fileMusicName = Guid.NewGuid().GetHashCode().ToString("x") + fuMusic.PostedFile.FileName;
                fileMusicName = listPostid + "_" + fileMusicName;
                fuMusic.PostedFile.SaveAs(Apath + "\\" + fileMusicName);

            }
            if (!string.IsNullOrEmpty(fileMusicName))
            {
                //tblpos = context.tblListPosition.Where(c => c.ListPosingId == tblpos.ListPosingId).FirstOrDefault();
                //if (tblpos != null)
                //{
                tblpos.Artistmusic = fileMusicName;
                context.SaveChanges();
                //}
            }

            if (FuMainimage.HasFile)
            {

                string Apath = Server.MapPath("~/ListPostingImage");
                if (!Directory.Exists(Apath))
                    Directory.CreateDirectory(Apath);

                fileMainName = Guid.NewGuid().GetHashCode().ToString("x") + FuMainimage.PostedFile.FileName;
                fileMainbig = listPostid + "_" + fileMainName;
                FuMainimage.PostedFile.SaveAs(Apath + "\\" + fileMainbig);

            }
            if (!string.IsNullOrEmpty(fileMainbig))
            {
                //tblpos = context.tblListPosition.Where(c => c.ListPosingId == tblpos.ListPosingId).FirstOrDefault();
                //if (tblpos != null)
                //{
                tblpos.MainImage = fileMainbig;
                context.SaveChanges();
                //}
            }

            if (fuImage.HasFile)
            {

                string Apath = Server.MapPath("~/ListPostingImage");
                if (!Directory.Exists(Apath))
                    Directory.CreateDirectory(Apath);

                fileName = Guid.NewGuid().GetHashCode().ToString("x") + fuImage.PostedFile.FileName;
                fileNameBig = listPostid + "_" + fileName;
                fuImage.PostedFile.SaveAs(Apath + "\\" + fileNameBig);

            }
            if (!string.IsNullOrEmpty(fileNameBig))
            {
                //tblpos = context.tblListPosition.Where(c => c.ListPosingId == tblpos.ListPosingId).FirstOrDefault();
                //if (tblpos != null)
                //{
                tblpos.ImageUrl = fileNameBig;
                context.SaveChanges();
                //}
            }



            if (fuHomeBanner.HasFile)
            {

                string Apath = Server.MapPath("~/HomeBanner");
                if (!Directory.Exists(Apath))
                    Directory.CreateDirectory(Apath);

                fileMainName = Guid.NewGuid().GetHashCode().ToString("x") + fuHomeBanner.PostedFile.FileName;
                fileMainbig = listPostid + "_" + fileMainName;
                fuHomeBanner.PostedFile.SaveAs(Apath + "\\" + fileMainbig);

            }
            if (!string.IsNullOrEmpty(fileMainbig))
            {
                //tblpos = context.tblListPosition.Where(c => c.ListPosingId == tblpos.ListPosingId).FirstOrDefault();
                //if (tblpos != null)
                //{
                tblpos.BannerImage = fileMainbig;
                context.SaveChanges();
                //}
            }

            if (fuHomeThumb.HasFile)
            {

                string Apath = Server.MapPath("~/HomeBanner");
                if (!Directory.Exists(Apath))
                    Directory.CreateDirectory(Apath);

                fileMainName = Guid.NewGuid().GetHashCode().ToString("x") + fuHomeThumb.PostedFile.FileName;
                fileMainbig = listPostid + "_" + fileMainName;
                fuHomeThumb.PostedFile.SaveAs(Apath + "\\" + fileMainbig);

            }
            if (!string.IsNullOrEmpty(fileMainbig))
            {
                //tblpos = context.tblListPosition.Where(c => c.ListPosingId == tblpos.ListPosingId).FirstOrDefault();
                //if (tblpos != null)
                //{
                tblpos.ThumnilImage = fileMainbig;
                context.SaveChanges();
                //}
            }

            //onLoadMethods.Append("self.parent.ClosePopupCallBack();");
            //ScriptManager.RegisterStartupScript(this, this.GetType(), "onLoadMsg", onLoadMethods.ToString(), true);

            Response.Redirect("ListPostings.aspx");
        }
        catch { }

    }

list view pagging and condtrol dynamicaly

//Put into body of the page



    <tr class="dividerLine">
        <td height="299" colspan="2" align="center" valign="top">
            <br />
            <table width='930' height='232' border='0' align='center' class='border'>

            <tr>
            <td align="right" style="padding-right: 20px;" class="smallTxt" colspan="2">
            <table > <tr>
            <td  > <asp:LinkButton ID="lnkbtnPrevious" runat="server" OnClick="lnkbtnPrevious_Click"><b>«</b></asp:LinkButton></td>
            <td >
            <asp:DataList ID="DataList2" runat="server"   CellPadding="1" CellSpacing="5" OnItemCommand="DataList2_ItemCommand"
                                            OnItemDataBound="DataList2_ItemDataBound" RepeatDirection="Horizontal">
                                            <ItemTemplate>
                                           
                                                <asp:LinkButton ID="lnkbtnPaging" runat="server" CommandArgument='<%# Eval("PageIndex") %>'
                                                    CommandName="lnkbtnPaging" CssClass="page_index" Text='<%# Eval("PageText") %>'></asp:LinkButton>
                                          
                                            </ItemTemplate>
                                        </asp:DataList></td>
            <td><asp:LinkButton ID="lnkbtnNext" runat="server" OnClick="lnkbtnNext_Click"><b>»</b></asp:LinkButton></td>
            </tr></table>
           
            </td>
            </tr>

                <tr>
                    <td height='20' valign='bottom'>
                        <div align='left' class='bodyTxt' style="padding-left: 25px;">
                            <asp:Label ID="lblname" runat="server" Text="By Artist" ></asp:Label>
                        </div>
                    </td>
                </tr>
              
                <tr>
                    <td>
                        <!-- DataList with images -->
                        <asp:DataList ID="dtlArtistGallery" RepeatDirection="Horizontal" RepeatColumns="5"
                            runat="server" onitemdatabound="dtlArtistGallery_ItemDataBound"
                            CssClass="photolist" >
                            <ItemTemplate>

                                <div class="smallTxt">
                                    <asp:LinkButton  runat="server" id="imgTitle" CommandName="linkPhoto" ToolTip='<%# Eval("title") +"(©"+Eval("copyright")+")"%>' class="smallTxt" PostBackUrl='<%#"by_artist.aspx?id="+ Eval("id") %>'>
                                        <img height="130" runat="server" id="img" width="130" alt='<%# Eval("title") %>' src='<%# "~/i/thumb/" + Eval("thumb_image") %>'
                                             class="border"/></asp:LinkButton>
                                             <p>
                                             <asp:LinkButton runat="server" id="lblTitle" CommandName="linkPhoto" ToolTip='<%# Eval("title") +"(©"+Eval("copyright")+")"%>'  PostBackUrl='<%#"by_artist.aspx?id="+ Eval("id") %>'>
                                        <asp:Label ID="lbltitlebottom" Text='<%# Eval("copyright") %>' runat="server"></asp:Label></asp:LinkButton>
                                             </p>
                                             <asp:HiddenField ID="hdnTitle" Value='<%#Eval("title") %>' runat="server" />
                                      </div>
                            </ItemTemplate>
                        </asp:DataList>
                   

                    </td>
                </tr>
                <tr>
                    <td height='20' valign='middle'>
                        &nbsp;
                    </td>
                </tr>
                 <tr>
            <td align="right" style="padding-right: 20px;" class="smallTxt" colspan="5">
            <table > <tr>
            <td> <asp:LinkButton ID="LinkButton1" runat="server" OnClick="lnkbtnPrevious_Click">«</asp:LinkButton></td>
            <td> <asp:DataList ID="DataList1" runat="server"   CellPadding="1" CellSpacing="5" OnItemCommand="DataList2_ItemCommand"
                                            OnItemDataBound="DataList2_ItemDataBound" RepeatDirection="Horizontal">
                                            <ItemTemplate>
                                                <asp:LinkButton ID="lnkbtnPaging" runat="server" CommandArgument='<%# Eval("PageIndex") %>'
                                                    CommandName="lnkbtnPaging" CssClass="page_index" Text='<%# Eval("PageText") %>'></asp:LinkButton>
                                            </ItemTemplate>
                                        </asp:DataList></td>
            <td><asp:LinkButton ID="LinkButton2" runat="server" OnClick="lnkbtnNext_Click"><b>»</b></asp:LinkButton></td>
            </tr></table>
           
            </td>
            </tr>

           

                <tr>
                    <td width="80%" align="center" class="my-data-list">

                   
                                   
                        <!-- DataList with Names -->
                        <asp:DataList ID="dtltitle" RepeatDirection="Horizontal" RepeatColumns="3" CellPadding="6" CellSpacing="1"
                            runat="server">
                            <ItemTemplate>

                                <div style="height:10px;">
                                    <a title='<%# Eval("fname") %>' class="bodyTxt" href='<%#"by_artist.aspx?id="+ Eval("id") %>'>
                                        <asp:Label ID="lbltitlebottom" Text='<%#Eval("fname")+" "+Eval("lname") %>' runat="server"></asp:Label></a></div>
                            </ItemTemplate>
                        </asp:DataList>
                       

                    </td>
                </tr>

               


            </table>
        </td>
    </tr>




//Source code use



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.Drawing;
public partial class by_artist1 : System.Web.UI.Page
{
    DataSet dsFeaturedArtists = new DataSet();
    DataTable dtArtistTitle = new DataTable();
    static int count = 0;
    int count1 = 0;
   
    PagedDataSource pds = new PagedDataSource();

    public int CurrentPage
    {
        get
        {
            if (this.ViewState["CurrentPage"] == null)
                return 0;
            else
                return Convert.ToInt16(this.ViewState["CurrentPage"].ToString());
        }
        set
        {
            this.ViewState["CurrentPage"] = value;
        }
    }


    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (string.IsNullOrEmpty(Request.QueryString["id"]))
            {
                dsFeaturedArtists = Artists.GetFeaturedArtists();
                dtArtistTitle = Artists.GetArtists();
                dtlArtistGallery.DataSource = dsFeaturedArtists.Tables[0];
                dtlArtistGallery.DataBind();
                dtltitle.DataSource = dtArtistTitle;
                dtltitle.DataBind();
                lnkbtnNext.Visible = false;
                lnkbtnPrevious.Visible = false;
                LinkButton1.Visible = false;
                LinkButton2.Visible = false;
            }
        }

        if (!string.IsNullOrEmpty(Request.QueryString["id"])) 
          
       {
          
               Session["last_page"] = "by_artist";
               Session["last_id"] = Request.QueryString["id"];
                dtArtistTitle = Artists.GetArtist(long.Parse(Request.QueryString["id"]));
                dsFeaturedArtists = Artists.GetActiveDisplayArtistPhotos(long.Parse(Request.QueryString["id"]));
                dtltitle.Visible = false;
                if(dtArtistTitle.Rows.Count!=0)
                lblname.Text = Convert.ToString(dtArtistTitle.Rows[0]["display_name"]);
                Bindlist();
           
       }

          
    

       
       
    }


   
    protected void Bindlist()
    {
       
       



        count = dsFeaturedArtists.Tables[1].Rows.Count;
        DataView dv = dsFeaturedArtists.Tables[1].DefaultView;
       
        pds.DataSource = dv;
        pds.AllowPaging = true;
        pds.PageSize = 40;
        pds.CurrentPageIndex = CurrentPage;
        lnkbtnNext.Enabled = !pds.IsLastPage;
        lnkbtnPrevious.Enabled = !pds.IsFirstPage;
        LinkButton1.Enabled = !pds.IsLastPage;
        LinkButton2.Enabled = !pds.IsFirstPage;
       
        lnkbtnNext.Visible = !pds.IsLastPage;
        lnkbtnPrevious.Visible = !pds.IsFirstPage;
        LinkButton2.Visible = !pds.IsLastPage;
        LinkButton1.Visible = !pds.IsFirstPage;
        dtlArtistGallery.DataSource = pds;
        dtlArtistGallery.DataBind();

      
        doPaging();

    }
    private void doPaging()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("PageIndex");
        dt.Columns.Add("PageText");

        for (int i = 0; i < pds.PageCount; i++)
        {
            DataRow dr = dt.NewRow();
            dr[0] = i;
            dr[1] = i + 1;
            dt.Rows.Add(dr);
        }

        DataList2.DataSource = dt;
        DataList2.DataBind();
        DataList1.DataSource = dt;
        DataList1.DataBind();
    }

    protected void dtlArtistGallery_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if(!string.IsNullOrEmpty(Request.QueryString["id"]))
        {
        Label lblimgTitle = (Label)e.Item.FindControl("lbltitlebottom");
        HiddenField hdnimgTitle = (HiddenField)e.Item.FindControl("hdnTitle");
        LinkButton lnkbtnimage = (LinkButton)e.Item.FindControl("imgTitle");
        LinkButton lnkbtntitle = (LinkButton)e.Item.FindControl("lblTitle");
        string strlnkimage = lnkbtnimage.PostBackUrl;
        lnkbtnimage.PostBackUrl=strlnkimage.Replace("by_artist.aspx?id=", "photo.aspx?id=");
        lnkbtntitle.PostBackUrl=strlnkimage.Replace("by_artist.aspx?id=", "photo.aspx?id=");
        hdnimgTitle.Value = hdnimgTitle.Value.Replace("&", "");
        hdnimgTitle.Value = hdnimgTitle.Value.Replace("#", "");

        int strLen2 = hdnimgTitle.Value.Length;
        if (strLen2 > 30)
        {
            hdnimgTitle.Value = hdnimgTitle.Value.Substring(0, 30);
            lblimgTitle.Text = hdnimgTitle.Value + "...[ ]";
        }
        else
        {
            lblimgTitle.Text = hdnimgTitle.Value;
        }
       
        }

        LinkButton lblimgTitle1 = (LinkButton)e.Item.FindControl("imgTitle");
        string strimgToolTip = Convert.ToString(lblimgTitle1.ToolTip);

        strimgToolTip = strimgToolTip.Replace("&", "");
        strimgToolTip = strimgToolTip.Replace("#", "");

        int strLen = strimgToolTip.Length;
        if (strLen > 50)
        {
            strimgToolTip = strimgToolTip.Substring(0, 50);
            lblimgTitle1.ToolTip = strimgToolTip.ToString() + "...[ ]";
        }
        else
        {
            lblimgTitle1.ToolTip = strimgToolTip.ToString();
        }

        LinkButton lbltxtTitle = (LinkButton)e.Item.FindControl("lblTitle");
        string strimgToolTip1 = Convert.ToString(lbltxtTitle.ToolTip);

        strimgToolTip1 = strimgToolTip1.Replace("&", "");
        strimgToolTip1 = strimgToolTip1.Replace("#", "");

        int strLen1 = strimgToolTip1.Length;
        if (strLen1 > 50)
        {
            strimgToolTip1 = strimgToolTip1.Substring(0, 50);
            lbltxtTitle.ToolTip = strimgToolTip1.ToString() + "...[ ]";
        }
        else
        {
            lbltxtTitle.ToolTip = strimgToolTip1.ToString();
        }

    }


    protected void lnkbtnPrevious_Click(object sender, EventArgs e)
    {
        CurrentPage -= 1;
        Bindlist();
    }
    protected void lnkbtnNext_Click(object sender, EventArgs e)
    {
        CurrentPage += 1;
        Bindlist();
    }
    protected void DataList2_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName.Equals("lnkbtnPaging"))
        {
            CurrentPage = Convert.ToInt16(e.CommandArgument.ToString());
            Bindlist();
        }
    }
    protected void DataList2_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemIndex == CurrentPage)
        {

            LinkButton lnkbtnpaging = (LinkButton)e.Item.FindControl("lnkbtnPaging");
            lnkbtnpaging.Enabled = false;


        }
   
    }

  

}


Work on Grid view with hendlar Stor image in database

//upload image in table

  protected void BtnSave_Click(object sender, EventArgs e)
        {

            string strBlogText = Convert.ToString(EdtBlogPost.Content);
            string strBlogTitle = Convert.ToString(txt_title.Text);
            string strBlogTag = Convert.ToString(txtTag.Text);
            int CategoryID = Convert.ToInt32(ddl_category.SelectedValue);

            int createdBy = Convert.ToInt32(Session["id"]);

            //if(BtnSave.Text=="SAVE"||BtnSave1.Text="SAVE")

            System.Web.UI.WebControls.FileUpload Country_img = (System.Web.UI.WebControls.FileUpload)FuBlogImage;
            Byte[] imgByte = null;
            if (FuBlogImage.HasFile && FuBlogImage.PostedFile != null)
            {
                HttpPostedFile File = FuBlogImage.PostedFile;
                imgByte = new Byte[File.ContentLength];
                File.InputStream.Read(imgByte, 0, File.ContentLength);
            }
            int check = 0;
            int check_update = 0;
            switch (BtnSave.Text)
            {
                case "SAVE":
                    {
                        check = objBlogPost.Ins_BlogPost(strBlogTitle, strBlogText, strBlogTag, CategoryID, createdBy, imgByte, 0, 0);
                        break;
                    }
                case "UPDATE":
                    {
                        if (FuBlogImage.HasFile && FuBlogImage.PostedFile != null)
                            check_update = objBlogPost.Ins_BlogPost(strBlogTitle, strBlogText, strBlogTag, CategoryID, createdBy, imgByte, 1, id1);
                        else
                            check_update = objBlogPost.UpdateBlog_WithoutImage(strBlogTitle, strBlogText, strBlogTag, CategoryID, createdBy, id1);
                        break;
                    }
                default:
                    break;

            }
            if (check > 0 || check_update > 0)
            {
                Response.Redirect("BlogPost_Grid.aspx");
                Session["msgOk"] = "Inserted Successfully";

            }

            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert(' Sorry!Try Again ')</script>");


            }

        }

// method called

public int Ins_BlogPost(string blogTitle, string blogText, string blogTag, int categoryID, int createdByID, Byte[] img, int mode, int BlogPostID)
        {
            int j = 0;

            switch (mode)
            {
                case 0:
                    {

                        j = context.fn_ins_blogpost(blogTitle, blogText, blogTag, categoryID, createdByID, true, img, 0, 0);
                        break;
                    }
                case 1:
                    {
                        j = context.fn_ins_blogpost(blogTitle, blogText, blogTag, categoryID, createdByID, true, img, 1, BlogPostID);
                        break;
                    }
                default:
                    break;

            }

            return j;
        }


//Call from row data bound


protected void gridBlogPost_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            if (e.Row.RowType == DataControlRowType.DataRow && (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate))
            {
                CheckBox chkBxSelect = (CheckBox)e.Row.Cells[1].FindControl("chkBxSelect");
                CheckBox chkBxHeader = (CheckBox)this.gridBlogPost.HeaderRow.FindControl("chkBxHeader");
                //CheckBox chkBx = (CheckBox)e.Row.Cells[2].FindControl("chkBx");
                chkBxSelect.Attributes["onclick"] = string.Format("javascript:ChildClick(this,'{0}');", chkBxHeader.ClientID);
            }

            if (e.Row.RowType == DataControlRowType.DataRow)
            {


                try
                {
                    Label labCreatedOn = (Label)e.Row.FindControl("labCreatedOn");

                    System.Web.UI.WebControls.Image img = (System.Web.UI.WebControls.Image)e.Row.FindControl("img_Blog");

                    img.ImageUrl = "~/BlogHendlar.ashx?id=" + DataBinder.Eval(e.Row.DataItem, "BlogPostID");
                    string strUrl = "~/BlogHendlar.ashx?id=" + DataBinder.Eval(e.Row.DataItem, "BlogPostID");
                    Session["tableName"] = "tblBlogPost";
                    //DateTime date1 =Convert.ToDateTime( lst[d].CreatedOn);labCreatedOn
                    DateTime date1 = Convert.ToDateTime(labCreatedOn.Text);
                    d++;
                    //IFormatProvider culture = new CultureInfo("en-GB");

                    string dateForm = date1.ToString("dd/MM/yyyy");

                    labCreatedOn.Text = date1.ToString("dd/MM/yyyy");


                    //ImageButton btn_Edit = (ImageButton)e.Row.FindControl("BtnEdit");
                    //btn_Edit.CommandArgument = strUrl;                                   // to find path of image

                    ImageButton imgStatus = (ImageButton)e.Row.FindControl("imgStatus");

                    imgStatus.CommandArgument = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "StatusID"))
                        + "/" + Convert.ToString(DataBinder.Eval(e.Row.DataItem, "BlogPostID"));

                    if (Convert.ToString(DataBinder.Eval(e.Row.DataItem, "StatusID")) == "True")
                    {
                        imgStatus.ImageUrl = "~/images/unblock.png";
                        imgStatus.ToolTip = "Click Here To Block";
                    }
                    else
                    {
                        imgStatus.ImageUrl = "~/images/block.png";
                        imgStatus.ToolTip = "Click Here To Unblock";
                    }

                    ImageButton BtnDelete = (ImageButton)e.Row.FindControl("imgbtnDelete");
                    BtnDelete.ImageUrl = "~/images/cross.png";



                }

                catch (Exception)
                {

                }
            }
        }




// Add handler page with name BlogHendlar.ashx

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

using System;
using System.Configuration;
using System.Web;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using BlogJobPortal.BL;
using BlogJobPortal.DL;
using System.Linq;



public class BlogHendlar : IHttpHandler
{
    clsBlogPost objblog = new clsBlogPost();

    public void ProcessRequest(HttpContext context)
    {
        Int32 county_Id;
        if (context.Request.QueryString["id"] != null)
            county_Id = Convert.ToInt32(context.Request.QueryString["id"]);
        else
            throw new ArgumentException("No parameter specified");


        context.Response.ContentType = "image/jpeg";
        Stream strm = ShowEmpImage(county_Id);
        byte[] buffer = new byte[1024];
        if (strm != null)
        {
        int byteSeq = strm.Read(buffer, 0, 1024); //4096
       
            while (byteSeq > 0)
            {
                context.Response.OutputStream.Write(buffer, 0, byteSeq);
                byteSeq = strm.Read(buffer, 0, 1024);
            }
        }//context.Response.BinaryWrite(buffer);
    }
    public Stream ShowEmpImage(int county_Id)
    {
        try
        {


          //  object img1 = objblog.BlogImage(county_Id).Single();



            string conn = Convert.ToString(ConfigurationManager.AppSettings["connectDb"]);
            SqlConnection connection = new SqlConnection(conn);
            //string tab=Convert.ToString(
            string sql = "SELECT [Image] FROM tblBlogPost WHERE BlogPostID = @ID";
            SqlCommand cmd = new SqlCommand(sql, connection);
            cmd.CommandType = CommandType.Text;
            cmd.Parameters.AddWithValue("@ID", county_Id);
            connection.Open();
            object img = cmd.ExecuteScalar();
            try
            {
                return new MemoryStream((byte[])img);
            }
            catch
            {
                return null;
            }
            finally
            {
                connection.Close();
            }
        }
        catch (Exception e)
        {
            return null;
        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

connection to database

//put into web.config
<connectionStrings>
        <add name="connectDb" connectionString="Data Source=DEEPAK;Initial Catalog=software;Integrated Security=True" providerName="System.Data.SqlClient"/>
    </connectionStrings>


//Call method



protected void btnSubmit_Click(object sender, EventArgs e)
    {
      
        string userLoginId = Convert.ToString(txtLoginId.Text);
        string Fname =Convert.ToString(txtfname.Text);
        string Lname = Convert.ToString(txtlname.Text);
        string Pass = Convert.ToString(txtpassword.Text);
        System.Web.UI.WebControls.FileUpload img = (System.Web.UI.WebControls.FileUpload)FileUpload1 ;
        Byte[] imgByte = null;
        if (img.HasFile && img.PostedFile != null)
        {
           
            HttpPostedFile File = FileUpload1.PostedFile;
           
            imgByte = new Byte[File.ContentLength];
           
            File.InputStream.Read(imgByte, 0, File.ContentLength);
        }

        int k=check();
        if (k == 0)
        {

            int id = Convert.ToInt32(genobj.regestration(userLoginId, Fname, Lname, Pass, imgByte));
            Response.Write(id);
            Response.Write("registered succesfully");
            Response.Redirect("dasbord.aspx");
           
        }
        else
        {
            Response.Write("Try again");

        }
      
    }





// call to database connection


 public DataTable login(String LogNm, String Pass)
    {
        SqlParameter[] param = new SqlParameter[2];

        param[0] = new SqlParameter("@LoginId", SqlDbType.NVarChar, 20);
        param[0].Direction = ParameterDirection.Input;
        param[0].Value = LogNm;

        param[1] = new SqlParameter("@Password", SqlDbType.NVarChar,100);
        param[1].Direction = ParameterDirection.Input;
        param[1].Value = Pass;
        DataTable dt = dbobj.checkLogin("Sp_LogIn", param);
        return dt;
    }

    public int checkLoginId(string loginId)
    {
        SqlParameter[] param = new SqlParameter[2];
        param[0] = new SqlParameter("@LoginId", SqlDbType.NVarChar, 20);
        param[0].Direction = ParameterDirection.Input;
        param[0].Value = loginId;

        param[1] = new SqlParameter("@ID", SqlDbType.Int);
        param[1].Direction = ParameterDirection.Output;

        DataTable dt = dbobj.checkLogin("SP_check_LoginId", param);
        int i=0;
        if (dt.Rows.Count > 0)
        {
            return i = 1;
        }
        else
        {
            return i;
        }
    }
    public int regestration(string LoginId, String fname, String lname, String password, Byte[] img)
    {
        SqlParameter[] param = new SqlParameter[6];

        param[0] = new SqlParameter("@FName", SqlDbType.NVarChar, 20);
        param[0].Direction = ParameterDirection.Input;
        param[0].Value = fname;

        param[1] = new SqlParameter("@LName", SqlDbType.NVarChar, 20);
        param[1].Direction = ParameterDirection.Input;
        param[1].Value = lname;

        param[2] = new SqlParameter("@Password", SqlDbType.NVarChar, 100);
        param[2].Direction = ParameterDirection.Input;
        param[2].Value = password;

        param[3] = new SqlParameter("@Image",SqlDbType.Image);
        param[3].Direction = ParameterDirection.Input;
        param[3].Value = img;

        param[4]=new SqlParameter("@LastId",SqlDbType.Int);
        param[4].Direction=ParameterDirection.Output;

        param[5] = new SqlParameter("@LoginId", SqlDbType.NVarChar);
        param[5].Direction = ParameterDirection.Input;
        param[5].Value = LoginId;

        int k=dbobj.DbInsert("Sp_registration",param);
        int id=0;
        if(k>0)
        {
         id=Convert.ToInt32(param[4].Value);

        }

        return id;
    }


// now create connection


 public void connectDb()
    {
        con = new SqlConnection(Convert.ToString(ConfigurationManager.AppSettings["connectDb"]));
        if (con.State == ConnectionState.Closed || con.State == ConnectionState.Broken)
        {
            con.Open();

        }
  
    }

//now call for coonection

public int DbInsert(string Spname, SqlParameter[] param)
    {
        connectDb();
        cmd = new SqlCommand(Spname, con);
        cmd.CommandType = CommandType.StoredProcedure;
        for (int i = 0; i < param.Length; i++)
        {
            cmd.Parameters.Add(param[i]);
        }
        int j = cmd.ExecuteNonQuery();
        con.Close();
        return j;
    }
    public DataTable checkLogin(string sp_Check, SqlParameter[] param)
    {
        connectDb();

        //cmd = new SqlCommand(sp_Check, con);
        //cmd.CommandType = CommandType.StoredProcedure;
        //for (int i = 0; i < param.Length; i++)
        //{
        //    cmd.Parameters.Add(param[i]);
        //}
        //int j = cmd.ExecuteNonQuery();
        //con.Close();
        //return j;
        da = new SqlDataAdapter(sp_Check,con);
        da.SelectCommand.CommandType = CommandType.StoredProcedure;
       
        for (int i = 0; i < param.Length; i++)
        {
            da.SelectCommand.Parameters.Add(param[i]);
        }
        DataTable dt = new DataTable();
        da.Fill(dt);

        return dt;
    }