Category subcategory


//html part



<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="BlogPost_Grid.aspx.cs" Inherits="BlogJobPortal.Web.BlogPost_Grid" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript">

      function DeleteConfirmation(Sel) {

          debugger; var hdSelectedItems = document.getElementById('<%= hdSelectedItems.ClientID%>').value;
          //    alert(hdSelectedItems);
          if (hdSelectedItems > 0) {
              if (confirm(hdSelectedItems + "   No. Of Row Selected " + "Sure! you want to" + " " + Sel + "  selected records ?") == true)
                  return true;
              else
                  return false;
          }
          else {
              alert(hdSelectedItems + "   No. Of Row Selected " + 'please select one item to' + " " + Sel);
              return false;
          }
      }
</script>
<script type="text/javascript">

    var TotalChkBx;
    var Counter;

    window.onload = function () {
        //Get total no. of CheckBoxes in side the GridView.
        TotalChkBx = parseInt('<%= this.gridBlogPost.Rows.Count %>');
        //Get total no. of checked CheckBoxes in side the GridView.
        Counter = 0;
    }

    function HeaderClick(CheckBox) {
        //Get target base & child control.
        var TargetBaseControl = document.getElementById('<%= this.gridBlogPost.ClientID %>');
        var TargetChildControl = "chkBxSelect";

        //Get all the control of the type INPUT in the base control.
        var Inputs = TargetBaseControl.getElementsByTagName("input");

        //Checked/Unchecked all the checkBoxes in side the GridView.
        for (var n = 0; n < Inputs.length; ++n)
            if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TargetChildControl, 0) >= 0)
                Inputs[n].checked = CheckBox.checked;
        //Reset Counter
        Counter = CheckBox.checked ? TotalChkBx : 0;
        document.getElementById('<%= hdSelectedItems.ClientID%>').value = Counter;
    }

    function ChildClick(CheckBox, HCheckBox) {
        //get target base & child control.
        var HeaderCheckBox = document.getElementById(HCheckBox);

        //Modifiy Counter;           
        if (CheckBox.checked && Counter < TotalChkBx)
            Counter++;
        else if (Counter > 0)
            Counter--;
        document.getElementById('<%= hdSelectedItems.ClientID%>').value = Counter;
        //Change state of the header CheckBox.
        if (Counter < TotalChkBx)
            HeaderCheckBox.checked = false;
        else if (Counter == TotalChkBx)
            HeaderCheckBox.checked = true;
    }

    </script>
    <title>Admin Panel</title>
    <style type="text/css">
        .style2
        {
            width: 182px;
        }
        .style7
        {
            width: 109px;
        }
        .style8
        {
            width: 151px;
        }
        .style9
        {
            width: 331px;
        }
        .style10
        {
            width: 750px;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div class="main">
  <div class="boxwrap">
   <div class="cormid">
       <p class="float-r">&nbsp;</p><h1>BlogPost</h1>
        <table>
        <tr><td class="style2"  align="right">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Category:</td><td class="style7">
            <asp:DropDownList ID="ddl_category" runat="server" Height="25px" Width="181px">
            </asp:DropDownList>
        </td><td width="100px" align="right"> Users:</td><td class="style8">
                <asp:DropDownList ID="DdlUsers" runat="server" Height="25px" Width="168px">
                </asp:DropDownList>
            </td><td class="style9">
                <asp:Button ID="BtnSearch" runat="server" CssClass="btn-blue1" Text="Search"
                    onclick="BtnSearch_Click" />
                <br />
            </td></tr>
        </table>
       
        <div class="stat"><a href="#"><asp:ImageButton ID="btnAddNew" ImageUrl="images/btn-addnew.gif" Text="ADD NEW"
                runat="server" CssClass="float-r" onclick="btnAddNew_Click"  /></a>
        <asp:Button ID="btn_Active" runat="server" Text="Active" CssClass="btn-blue1"
                onclick="btn_Active_Click" ToolTip="Click Here To See Activate Only"  />
         &nbsp; &nbsp; &nbsp;<asp:Button ID="btnInactive" runat="server" Text="Inactive"
                CssClass="btn-blue1" onclick="btnInactive_Click" ToolTip="Click Here To See Deactivate Only " />
                &nbsp; &nbsp; &nbsp;<asp:Button ID="btn_All_Select" runat="server" Text="View All"
                CssClass="btn-blue1" onclick="btn_All_Select_Click" ToolTip="Click Here To View All "   />
        </div>
        <div class="stat"><table height="20px"><tr><td  ><asp:Label ID="Label2" Font-Size="X-Large" Font-Bold="true" runat="server"></asp:Label></td>
        <td class="style10" align="center"><asp:Label ID="lblMSG" ForeColor="Green" Font-Bold="true"  runat="server"></asp:Label></td></tr></table>   </div>
        <div class="grid">
      
        <div class="topbar">
        <asp:HiddenField ID="hdSelectedItems" runat="server" Value="0" />
            <asp:Button ID="button1" runat="server" Text="activate Selected"
                CssClass="btn-active" onclick="btn_activeAll" OnClientClick="return DeleteConfirmation('Activate');" ToolTip="Click Here To Activate Selected " />  |
            <asp:Button ID="Btn_DeactiveAll"
                runat="server" Text="Deactivate Selected" CssClass="btn-deactive" onclick="button_Click" OnClientClick="return DeleteConfirmation('Deactivate');" ToolTip="Click Here To Deactivate Selected "
               /> |
            <asp:Button ID="btnDelete" Text="Delete Selected" runat="server"
                CssClass="btn-delete" onclick="btnDelete_Click"  OnClientClick="return DeleteConfirmation('Delete');" ToolTip="Click Here To Delete Selected "/>
        </div>
        <div class="wrapp">
        <asp:GridView ID="gridBlogPost" runat="server" AutoGenerateColumns="false"
                Width="917px"  DataKeyNames="BlogPostID"
                 GridLines="None" PagerSettings-Mode="Numeric" AllowPaging="true"
                onrowcommand="gridBlogPost_RowCommand"
                onrowdeleting="gridBlogPost_RowDeleting"
                onrowdatabound="gridBlogPost_RowDataBound"
                onpageindexchanging="gridBlogPost_PageIndexChanging" PageSize="10"  >
           
        <Columns>

            <asp:TemplateField>
           
            <HeaderTemplate>
            <asp:CheckBox ID="chkBxHeader" onclick="javascript:HeaderClick(this);" runat="server" />
           
            </HeaderTemplate>
           
         
            <ItemTemplate>
              <asp:CheckBox ID="chkBxSelect" runat="server"  />
                 <asp:HiddenField ID="hdnID" Value='<%#Eval("BlogPostID") %>' runat="server" />
            </ItemTemplate>
           
           </asp:TemplateField>
           <asp:TemplateField HeaderText="Title">
           <ItemTemplate>
           <asp:Label id="lblBlogTitle" runat="server" Text='<%#Eval("BlogPostTitle") %>'></asp:Label>
           </ItemTemplate>
           </asp:TemplateField>
          
              
            <asp:TemplateField HeaderText="image">
      <ItemTemplate>
      <asp:Image ID="img_Blog" runat="server" Height="30px" Width="50px" />
     
      </ItemTemplate>
      <EditItemTemplate>
      <asp:FileUpload ID="fu_country_image" runat="server" />
          
      </EditItemTemplate>
            </asp:TemplateField>
           
           
           <asp:TemplateField HeaderText="CreatedBy">
            <ItemTemplate>
            <asp:Label ID="lblCreatedBy" runat="server" Text='<%#Eval("UserName") %>' ></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
            <asp:TextBox ID="txtCountryName" runat="server" Text='<%#Eval("country_Title") %>' ></asp:TextBox>
            </EditItemTemplate>
             </asp:TemplateField>
          
            <asp:TemplateField HeaderText="CreatedOn">
            <ItemTemplate>
            <asp:Label ID="labCreatedOn" runat="server" Text='<%#Eval("CreatedOn") %>' ></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
            <asp:TextBox ID="txt_country_code" Text='<%#Eval("country_Code") %>' runat="server"></asp:TextBox>
            </EditItemTemplate>
             </asp:TemplateField>
           
     
           
             <asp:TemplateField HeaderText="Action">
             <ItemTemplate>
             <asp:ImageButton id="imgbtnView" runat="server" ImageUrl="~/images/iconedit.png"  CommandName="ViewDetail" Width="20px"   Height="20px"  />&nbsp; &nbsp;  
            <asp:ImageButton ID="imgStatus" runat="server" CommandName="activeInactive" Width="20px"   Height="20px"  /> &nbsp; &nbsp;           
           <asp:ImageButton ID="imgbtnDelete" runat="server"  CommandName="delete" ToolTip="Click Here To Delete" OnClientClick="return confirm('Sure want To Delete?')" />&nbsp; &nbsp;
           <asp:ImageButton ID="BtnEdit" Text="Edit" runat="server" ImageUrl="~/images/iconedit.png"  CommandName="Edit" ToolTip="Click Here To Edit" OnClientClick="return confirm('Sure want To Edit?')" />
             <asp:ImageButton id="imgBtnComment" runat="server" CommandName="Comment" Width="20px" ImageUrl="~/images/iconedit.png" CommandArgument='<%#Eval("CreatedByID") %>'   Height="20px"  ToolTip="Click Here To View Comments" OnClientClick="return confirm('Sure want To View Comments ?')"  />&nbsp; &nbsp; 
              </ItemTemplate>
            </asp:TemplateField>
           
        </Columns>
        </asp:GridView>
       
        </div>
       
        </div>
    </div>
    <div class="corbot"></div>
    </div>
   </div>

</asp:Content>


// Back code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;
using System.Globalization;
using BlogJobPortal.BL;
using BlogJobPortal.DL;
using BlogJobPortal.Web;

namespace BlogJobPortal.Web
{
    public partial class BlogPost_Grid : System.Web.UI.Page
    {
        List<Comp_BlogPost_gridbind> lst = new List<Comp_BlogPost_gridbind>();
        ClassBL objClassBL = new ClassBL();
        clsBlogPost objBlogPost = new clsBlogPost();
        List<tblAdminOfUser> lstuser = new List<tblAdminOfUser>();
        Class1 objclass1 = new Class1();
        string status = null;
        int level = -1;
        int d = 0;
        private static List<T_Category> lst_ParentCategory = new List<T_Category>();
        List<T_Category> lstfind = new List<T_Category>();
        int id;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["id"] == null)
            {
                Response.Redirect("loginPage.aspx");
            }
            if (!IsPostBack)
            {
                ddlUser_bind();
                CategoryDrordownBind();
                bindgrid();
            }
            lblMSG.Text = Convert.ToString(Session["msg"]);

        }

        protected void bindgrid()
        {

            lst = objBlogPost.grid_bind().ToList();
            gridBlogPost.DataSource = lst;
            gridBlogPost.DataBind();


        }
        public void ddlUser_bind()
        {

            lstuser = objBlogPost.ddluser_bind().ToList();
            DdlUsers.DataSource = lstuser;
            DdlUsers.DataTextField = "UserName";
            DdlUsers.DataValueField = "AdminId";
            DdlUsers.DataBind();
            DdlUsers.Items.Insert(0, new ListItem("Select User", "0"));
        }
        public void CategoryDrordownBind()
        {
            DataTable dtParent = new DataTable();
            //List<T_Category> lst_ParentCategory = new List<T_Category>();
            lst_ParentCategory = objclass1.Category_Table_return().ToList();
            dtParent.Columns.Add("CategoryID", typeof(int));
            dtParent.Columns.Add("CategoryName", typeof(string));
            dtParent.Columns.Add("ProductCategoryID", typeof(string));
            dtParent.Columns.Add("Status", typeof(bool));


            foreach (T_Category lst in lst_ParentCategory)
            {
                dtParent.Rows.Add(lst.CategoryID, lst.CategoryName, lst.ProductCategoryID, lst.Status);
            }

            ////Or..............

            //for (int k = 0; k < lst_ParentCategory.Count; k++)
            //{
            //    dtParent.Rows.Add(lst_ParentCategory[k].CategoryID, lst_ParentCategory[k].CategoryName, lst_ParentCategory[k].ProductCategoryID, lst_ParentCategory[k].Status);

            //}
            RecursiveFillTree(dtParent, 0);


            ddl_category.Items.Insert(0, new ListItem("Select category", "0"));

            //RecursiveFillTree(lst_ParentCategory, 0);
            // = Convert.ChangeType(lst,DataTable);
            //System.Collections.Generic.List<T_Category> obj = new System.Collections.Generic.List<T_Category>();
            //DataTable dt = GenericToDataTable.ConvertTo<T_Category>(obj);

        }

        private void RecursiveFillTree(DataTable dtParent, int parentID)
        {
            level++; //on the each call level increment 1 
            StringBuilder appender = new StringBuilder();
            for (int j = 0; j < level; j++)
                appender.Append("&nbsp;&nbsp;");
            if (level > 0)
                appender.Append("|__");

            DataView dv = new DataView(dtParent);
            dv.RowFilter = string.Format("ProductCategoryID = {0}", parentID);
            int i;
            if (dv.Count > 0)
            {
                for (i = 0; i < dv.Count; i++)
                {
                    ddl_category.Items.Add(new ListItem(Server.HtmlDecode(appender.ToString() + dv[i]["CategoryName"].ToString()), dv[i]["CategoryID"].ToString()));
                    RecursiveFillTree(dtParent, int.Parse(dv[i]["CategoryID"].ToString()));

                }
            }
            level--; //on the each function end level will decrement by 1 
        }
        protected void btnAddNew_Click(object sender, EventArgs e)
        {

        }
        protected void btn_All_Select_Click(object sender, EventArgs e)
        {
            bindgrid();

        }
        protected void btnInactive_Click(object sender, EventArgs e)
        {
            BindActiveInactive(0);
        }
        protected void btn_Active_Click(object sender, EventArgs e)
        {
            BindActiveInactive(1);

        }
       

        protected void BindActiveInactive(int b)
        {

            List<Comp_BlogPost_gridbind> lst = new List<Comp_BlogPost_gridbind>();
            lst = objBlogPost.Bind_active_inactive(b,Convert.ToInt16( ddl_category.SelectedValue),Convert.ToInt32( DdlUsers.SelectedValue)).ToList();
            gridBlogPost.DataSource = lst;
            gridBlogPost.DataBind();
        }
        protected void btn_activeAll(object sender, EventArgs e)
        {
            int count = 0;
            //int[] arryID = new int[20];
            List<int> lstId = new List<int>();
            int i = 0;
            foreach (GridViewRow gvr in gridBlogPost.Rows)
            {
                CheckBox chk1 = (CheckBox)gvr.FindControl("chkBxSelect");
                //bool result = ClientScript.RegisterClientScriptBlock("Confirm", "<script>confirm('wanna delete?');</script>");
                HiddenField hdn = (HiddenField)gvr.FindControl("hdnID");
                if (chk1.Checked)
                {
                    lstId.Add(Convert.ToInt32(hdn.Value));
                    //arryID[i] = Convert.ToInt32(hdn.Value);
                    //delete(query);
                    i++;
                    count++;
                }
            }
            if (count > 0)
            {
                try
                {
                    //ClientScript.RegisterStartupScript(this.GetType(), "", "<script>confirm(' Sure U want to delete ')</script>");
                    objBlogPost.activate_deactivate_all(lstId, 1);

                    bindgrid();
                }
                catch (Exception ex)
                {
                    //ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('" + ex.Message.ToString() + "')</script>");
                }
            }
            else
            {
                // lblErrorMsg.Text = "please select at least one to Activate.";
                //ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('select first ')</script>");
            }
        }
        protected void button_Click(object sender, EventArgs e)
        {
            int count = 0;
            //int[] arryID = new int[20];
            List<int> lstId = new List<int>();
            int i = 0;
            foreach (GridViewRow gvr in gridBlogPost.Rows)
            {
                CheckBox chk1 = (CheckBox)gvr.FindControl("chkBxSelect");
                //bool result = ClientScript.RegisterClientScriptBlock("Confirm", "<script>confirm('wanna delete?');</script>");
                HiddenField hdn = (HiddenField)gvr.FindControl("hdnID");
                if (chk1.Checked)
                {
                    lstId.Add(Convert.ToInt32(hdn.Value));
                    //arryID[i] = Convert.ToInt32(hdn.Value);
                    //delete(query);
                    i++;
                    count++;
                }
            }
            if (count > 0)
            {
                try
                {
                    //ClientScript.RegisterStartupScript(this.GetType(), "", "<script>confirm(' Sure U want to delete ')</script>");
                    objBlogPost.activate_deactivate_all(lstId, 2);

                    bindgrid();
                }
                catch (Exception ex)
                {
                    //ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('" + ex.Message.ToString() + "')</script>");
                }
            }
            else
            {
                //lblErrorMsg.Text = "please select at least one to Activate.";
                //ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('select first ')</script>");
            }
        }
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            int count = 0;
            //int[] arryID = new int[20];
            List<int> lstId = new List<int>();
            int i = 0;
            foreach (GridViewRow gvr in gridBlogPost.Rows)
            {
                CheckBox chk1 = (CheckBox)gvr.FindControl("chkBxSelect");
                //bool result = ClientScript.RegisterClientScriptBlock("Confirm", "<script>confirm('wanna delete?');</script>");
                HiddenField hdn = (HiddenField)gvr.FindControl("hdnID");
                if (chk1.Checked)
                {
                    lstId.Add(Convert.ToInt32(hdn.Value));
                    //arryID[i] = Convert.ToInt32(hdn.Value);
                    //delete(query);
                    i++;
                    count++;
                }
            }
            if (count > 0)
            {
                try
                {
                    //ClientScript.RegisterStartupScript(this.GetType(), "", "<script>confirm(' Sure U want to delete ')</script>");
                    objBlogPost.delete_selected(lstId);

                    bindgrid();
                }
                catch (Exception ex)
                {
                    //ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('" + ex.Message.ToString() + "')</script>");
                }
            }


        }


        protected void gridBlogPost_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {


            int id = Convert.ToInt32(gridBlogPost.DataKeys[e.RowIndex].Value);
            int checkdel = objBlogPost.DeleteRow(id);

            if (checkdel > 0)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('deleted sucessfully')</script>");
                bindgrid();
            }
            else
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('Try Again')</script>");
        }


        protected void gridBlogPost_RowCommand(object sender, GridViewCommandEventArgs e)
        {
           
            if (e.CommandName == "activeInactive")
            {
                 GridViewRow grv = (GridViewRow)((ImageButton)e.CommandSource).Parent.Parent;
                string str = Convert.ToString(e.CommandArgument);
                string[] strsplit = new string[2];
                strsplit = str.Split('/');                         // to split value manish/deepak it treats two value manish and deepak
                int categoryID = Convert.ToInt32(strsplit[1]);
                status = Convert.ToString(strsplit[0]);

                //if (status == "True")
                //{

                //    imgStatus.OnClientClick = "return confirm('Sure want To Unblock?')";
                //}
                //else if(status == "false")
                //{
                //    imgStatus.OnClientClick = "return confirm('Sure want To Block?')";
                //}

                BlockUnblock(status == "True" ? false : true, categoryID);



                bindgrid();

            }

            //GridViewRow grv = (GridViewRow)((Button)e.CommandSource).Parent.Parent;
            if (e.CommandName == "Edit")
            {
                GridViewRow grv = (GridViewRow)((ImageButton)e.CommandSource).Parent.Parent;
                // to find row
                int id = Convert.ToInt32(gridBlogPost.DataKeys[grv.RowIndex].Value);

                //string url = Convert.ToString(e.CommandArgument);
                //Session["url"] = url;
                Response.Redirect("BlogPost_Form.aspx?id=" + id);

            }
            if (e.CommandName == "ViewDetail")
            {
                GridViewRow grv = (GridViewRow)((ImageButton)e.CommandSource).Parent.Parent;
                // to find row
                int id = Convert.ToInt32(gridBlogPost.DataKeys[grv.RowIndex].Value);


                Response.Redirect("BlogPost_viewDetail.aspx?id=" + id);

            }
            if (e.CommandName == "Comment")
            {
                GridViewRow grv = (GridViewRow)((ImageButton)e.CommandSource).Parent.Parent;
                // to find row
                int id = Convert.ToInt32(gridBlogPost.DataKeys[grv.RowIndex].Value);
                Label lblCreatedBy = (Label)grv.FindControl("lblCreatedBy");
                Session["intCreatedBy"] = Convert.ToString(e.CommandArgument);
                Session["intBlogPostID"] = Convert.ToInt32(id);
                Response.Redirect("Comment_Grid_Display.aspx?id=" + id);

            }


        }

        public void BlockUnblock(bool status, int i)
        {
            int s;
            if (status == true)
            {
                s = 1;
            }
            else
                s = 0;
            objBlogPost.StatusUpdate(i, s);

        }



        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)
                {

                }
            }
        }
        protected void BtnSearch_Click(object sender, EventArgs e)
        {
            int categoryId = Convert.ToInt32(ddl_category.SelectedValue);
            int createdById = Convert.ToInt32(DdlUsers.SelectedValue);
            List<Comp_BlogPost_gridbind> lst = new List<Comp_BlogPost_gridbind>();
            lst = objBlogPost.Search_BindGrid(categoryId, createdById).ToList();
            gridBlogPost.DataSource = lst;
            gridBlogPost.DataBind();
        }
        protected void btnAddNew_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("BlogPost_Form.aspx");
        }

        protected void gridBlogPost_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gridBlogPost.PageIndex = e.NewPageIndex;
            bindgrid();
        }

    }
}



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 { }

    }