Pages

Subscribe:

Thursday, 29 January 2015

Change label into textbox using jquery

<div>
    <div id="tagCust">Customer Details<img src="images/edit.png" class="alignright"/></div>
</div>

<div id="contactdetail">
    <div id="contactInfo">
        <label for="emailid" class="contactText" data-inline="true">Email Id*</label>
    </div>
         <label for="mobileno" class="contactText" data-inline="true">Mobile No.</br></label>
         <label for="custid" class="contactText" data-inline="true">Customer Id.</label>
</div>
 
$('.alignright').on('click', function() {
    $('label.contactText').slice(0,2).each(function() {
        $(this).replaceWith( '<input type="text"/>' );
    });
});
 
$("label").each(function(){
        if(($(this).attr("for") == "emailid")||($(this).attr("for") == "mobileno")){
           $(this).after("<input type='text' id='"+ $(this).attr("for") +"'/>");
           $(this).hide();
        }
    });  

Sunday, 18 January 2015

Upload PDF

  FileUpload fl1 = (FileUpload)pnl2.FindControl("FileUpload2");
                UploadImage(fl1);
                sPath1 = UploadImage(fl1);
                if (sPath1 == "File size cannot be larger than 2 MB")
                {
                    lblSuccess.Text = sPath1;
                    return;
                }

 private string UploadImage(FileUpload fl)
    {
        string sSavePath = string.Empty;
        string sSavePath1 = string.Empty;
        string sFilename = string.Empty;
        string msg = string.Empty;
        Random RandomClass = new Random();
        int RandomNumber1 = RandomClass.Next(1000, 9000);

        // Set constant values
        string type = fl.PostedFile.ContentType;

        //code for jpg file
        if (fl.HasFile && checkImageContentType(fl.PostedFile.ContentType))
        {
            // HttpPostedFile fl = fl.PostedFile;
            if (fl.PostedFile.ContentType != "application/pdf")
            {
                System.Drawing.Image oImage = System.Drawing.Image.FromStream(fl.PostedFile.InputStream);
                if (oImage.Width > 150 || oImage.Height > 150)
                {
                    lblSuccess.Text = "Image is greater than 150 * 150";
                    completepath = lblSuccess.Text.ToString();
                    return completepath;
                }
                else
                {
                    sSavePath = "Brochure/";
                    sFilename = fl.FileName;
                    sFilename = "Press" + Convert.ToString(Session["exid"]) + RandomNumber1 + "_" + fl.FileName;
                    fl.SaveAs(Server.MapPath(sSavePath + sFilename));
                    completepath = sSavePath + sFilename;
                    return completepath;
                }
            }
            else
            {
                if (((Convert.ToDecimal(fl.PostedFile.ContentLength) / 1024) / 1024) > 2)
                {

                    lblSuccess.Text = "File size cannot be larger than 2 MB";
                    return lblSuccess.Text;
                }
                else
                {
                    sSavePath = "PDF/";
                    sFilename = "Press_" + Convert.ToString(Session["exid"]) + RandomNumber1 + "_" + fl.FileName;
                    fl.SaveAs(Server.MapPath(sSavePath + sFilename));
                    completepath = sSavePath + sFilename;
                    return completepath;
                }
            }
        }
        else
        {
            return msg;
        }
    }
    public static bool checkImageContentType(string contentType)
    {
        //check whether the uploaded file is an image or not
        if (contentType == "image/gif" || contentType == "image/jpeg" || contentType == "image/pjpeg" || contentType == "application/pdf")
            return true;
        else
            return false;
    }

 <asp:FileUpload ID="FileUpload2" runat="server" />
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="FileUpload2"
                                            ErrorMessage="Required" Display="Dynamic">Required</asp:RequiredFieldValidator><br />
                                        <asp:RegularExpressionValidator ID="RevDoc" runat="server" ControlToValidate="FileUpload2"
                                            ErrorMessage="select only PDF file." ValidationExpression="^.+(.pdf)$" Display="Dynamic"><span style="color: Red">select only PDF file</span> </asp:RegularExpressionValidator>
                                        <a id="Pdf" target="_blank" runat="server"></a><span id="err2" style="color: Red">

Find Row Index in gridView

 DataKeyNames="id"
<Columns>
                                                <asp:TemplateField HeaderText="NO." HeaderStyle-HorizontalAlign="Left" Visible="false">
                                                    <ItemTemplate>
                                                        <asp:Label ID="lblSNo" runat="server" Text='<%# Eval("SrNo")%>'></asp:Label>
                                                        <asp:Label ID="hdSeq" runat="server" Text='<%# Eval("ItemOrder")%>' Visible="false" />
                                                    </ItemTemplate>
                                                    <ItemStyle HorizontalAlign="Left" />
                                                </asp:TemplateField>
                                                <asp:BoundField DataField="Press_Title" HeaderText="Press Release" HeaderStyle-HorizontalAlign="Left"
                                                    ItemStyle-HorizontalAlign="Left" />
                                                <%--<asp:ButtonField CommandName="edt" HeaderText="Edit" Text="Edit" HeaderStyle-HorizontalAlign="Left" />--%>
                                                <asp:TemplateField HeaderText="Edit" HeaderStyle-Width="10%" ItemStyle-HorizontalAlign="Center">
                                                    <ItemTemplate>
                                                        <asp:LinkButton ID="btnedit" runat="server" CommandName="edt" CommandArgument='<%# Eval("specialid") %>'
                                                            CausesValidation="False">Edit</asp:LinkButton>
                                                    </ItemTemplate>
                                                    <HeaderStyle HorizontalAlign="Center" />
                                                </asp:TemplateField>
                                                <asp:TemplateField HeaderText="Status">
                                                    <ItemTemplate>
                                                        <asp:LinkButton ID="LinkButton1" runat="server" Text='<%# Eval("Press_status") %>'
                                                            CommandName="Change" CommandArgument='<%# Eval("specialid") %>' CausesValidation="False"
                                                            OnClick="LinkButton1_Click"></asp:LinkButton>
                                                    </ItemTemplate>
                                                    <HeaderStyle HorizontalAlign="Left" />
                                                </asp:TemplateField>
                                                <asp:TemplateField HeaderText="Up" HeaderStyle-Width="10%" HeaderStyle-HorizontalAlign="Left">
                                                    <ItemTemplate>
                                                        <asp:LinkButton ID="lnkup" CausesValidation="false" runat="server" CommandName="Up"
                                                            Visible="false">
                                                            <asp:Image ID="imgUp" runat="server" ImageUrl="images/up_red.gif" />
                                                        </asp:LinkButton>
                                                    </ItemTemplate>
                                                </asp:TemplateField>
                                                <asp:TemplateField HeaderText="Down" HeaderStyle-Width="10%" HeaderStyle-HorizontalAlign="Left">
                                                    <ItemTemplate>
                                                        <asp:LinkButton ID="lnkdown" CausesValidation="false" runat="server" CommandName="Down"
                                                            Visible="false">
                                                            <asp:Image ID="imgDown" runat="server" ImageUrl="images/down_red.gif" />
                                                        </asp:LinkButton>
                                                    </ItemTemplate>
                                                </asp:TemplateField>
                                            </Columns>

 protected void LinkButton1_Click(object sender, EventArgs e)
    {
        LinkButton lb1 = (LinkButton)sender;
        GridViewRow row = (GridViewRow)lb1.NamingContainer;
        Session["Index"] = row.RowIndex;
    }



if (e.CommandName == "edt" || e.CommandName == "Change" || e.CommandName == "Up" || e.CommandName == "Down")
            {
                GridViewRow row = (GridViewRow)((Control)e.CommandSource).NamingContainer;

                int index = Convert.ToInt32(row.RowIndex);
                string sProdId = GridView1.DataKeys[index].Value.ToString();
                if (e.CommandName == "Change")
                {
                    Session["spcloffer"] = e.CommandArgument;
                }
                else if (e.CommandName == "edt")
                {
                    Session["spcloffer"] = Convert.ToString(e.CommandArgument);
                    using (SqlCommand cmd = new SqlCommand("Sp_ManageExhibitorPress", Conn))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        using (SqlDataAdapter da = new SqlDataAdapter())
                        {
                            da.SelectCommand = cmd;
                            da.SelectCommand.Parameters.AddWithValue("@eventid", Session["eventid"].ToString());
                            da.SelectCommand.Parameters.AddWithValue("@exid", Convert.ToString(Session["exid"]));
                            da.SelectCommand.Parameters.AddWithValue("@specialId", Convert.ToString(Session["spcloffer"]));
                            da.SelectCommand.Parameters.AddWithValue("@flag", "GRID_MODIFY");
                            da.SelectCommand.Parameters.AddWithValue("@RecordCount", 0);
                            da.SelectCommand.Parameters["@RecordCount"].Direction = ParameterDirection.Output;
                            //Response.Write("test-" + Session["eventid"].ToString() + "-" + Session["exid"].ToString() + "-" + Convert.ToString(Session["spcloffer"]));
                            using (DataTable dt = new DataTable())
                            {
                                da.Fill(dt);
                                if (dt != null && dt.Rows.Count > 0)
                                {
                                    lblSuccess.Text = "";
                                    txtProductName.Text = dt.Rows[0]["Press_Title"].ToString();
                                    txtProductDescription.Text = dt.Rows[0]["Press_desc"].ToString();
                                    if (!string.IsNullOrEmpty(Convert.ToString(dt.Rows[0]["Press_pdf"])))
                                    {
                                        Pdf.HRef = Convert.ToString(dt.Rows[0]["Press_pdf"]);
                                        Pdf.InnerText = "View";
                                    }


                                }
                                btnSubmit.Visible = false;
                                btnUpdate.Visible = true;
                            }
                        }
                    }
                }

                switch (e.CommandName.ToLower())
                {

                    case "change":

                        LinkButton lb = (LinkButton)GridView1.Rows[Convert.ToInt32(Session["Index"].ToString())].Cells[0].FindControl("LinkButton1");
                        string status = string.Empty;
                        if (lb.Text == "Valid")
                        {
                            status = "Invalid";
                        }
                        else
                        {
                            status = "Valid";
                        }
                        using (SqlCommand cmd = new SqlCommand("Sp_ManageExhibitorPress", Conn))
                        {
                            cmd.CommandType = CommandType.StoredProcedure;
                            cmd.Parameters.AddWithValue("@specialId", Convert.ToString(Session["spcloffer"]));
                            cmd.Parameters.AddWithValue("@eventid", Session["eventid"].ToString());
                            cmd.Parameters.AddWithValue("@exid", Session["exid"].ToString());
                            cmd.Parameters.AddWithValue("@special_status", status);
                            cmd.Parameters.AddWithValue("@flag", "UPDATE_STATUS");
                            cmd.Parameters.AddWithValue("@RecordCount", 0);
                            cmd.Parameters["@RecordCount"].Direction = ParameterDirection.Output;
                            Conn.Open();
                            cmd.ExecuteNonQuery();
                            if (cmd.Parameters["@RecordCount"].Value != DBNull.Value)
                            {
                                Conn.Close();
                                lblSuccess.Text = "Records Modified Successfully!";
                            }
                            else
                            {
                                lblSuccess.Text = "Seems Some Problem! Please try again later.";
                            }
                        }
                        break;
                    case "up":
                        {
                            Label Newhd = (Label)GridView1.Rows[index - 1].FindControl("hdSeq");
                            Label hd = (Label)GridView1.Rows[index].FindControl("hdSeq");
                            int NewSeqno = Convert.ToInt32(Newhd.Text);
                            int Seqno = Convert.ToInt32(hd.Text);
                            string sNewProdId = GridView1.DataKeys[index - 1].Value.ToString();
                            using (SqlCommand cmd = new SqlCommand("Sp_ManageExhibitorPress", Conn))
                            {
                                ///<summary>
                                ///this procedure uses table tblProds to update the order in the
                                /// products will be displayed for this exhibitors
                                ///</summary>
                                cmd.CommandType = CommandType.StoredProcedure;
                                cmd.Parameters.AddWithValue("@eventid", Session["eventid"].ToString());
                                cmd.Parameters.AddWithValue("@exid", Session["exid"].ToString());
                                cmd.Parameters.AddWithValue("@sequenceNo", Seqno);
                                cmd.Parameters.AddWithValue("@newSequenceNo", NewSeqno);
                                cmd.Parameters.AddWithValue("@specialId", sProdId);
                                cmd.Parameters.AddWithValue("@newspecialId", sNewProdId);
                                cmd.Parameters.AddWithValue("@flag", "GRID_UP");
                                cmd.Parameters.AddWithValue("@RecordCount", 0);
                                cmd.Parameters["@RecordCount"].Direction = ParameterDirection.Output;
                                Conn.Open();
                                cmd.ExecuteNonQuery();
                                Conn.Close();
                            }
                        }
                        break;
                    case "down":
                        {
                            Label Newhd = (Label)GridView1.Rows[index + 1].FindControl("hdSeq");
                            Label hd = (Label)GridView1.Rows[index].FindControl("hdSeq");
                            int NewSeqno = Convert.ToInt32(Newhd.Text);
                            int Seqno = Convert.ToInt32(hd.Text);
                            string sNewProdId = GridView1.DataKeys[index + 1].Value.ToString();
                            using (SqlCommand cmd = new SqlCommand("Sp_ManageExhibitorPress", Conn))
                            {
                                ///<summary>
                                ///this procedure uses table tblProds to update the order in the
                                /// products will be displayed for this exhibitors
                                ///</summary>
                                cmd.CommandType = CommandType.StoredProcedure;
                                cmd.Parameters.AddWithValue("@eventid", Session["eventid"].ToString());
                                cmd.Parameters.AddWithValue("@exid", Session["exid"].ToString());
                                cmd.Parameters.AddWithValue("@sequenceNo", Seqno);
                                cmd.Parameters.AddWithValue("@newSequenceNo", NewSeqno);
                                cmd.Parameters.AddWithValue("@specialId", sProdId);
                                cmd.Parameters.AddWithValue("@newspecialId", sNewProdId);
                                cmd.Parameters.AddWithValue("@flag", "GRID_UP");
                                cmd.Parameters.AddWithValue("@RecordCount", 0);
                                cmd.Parameters["@RecordCount"].Direction = ParameterDirection.Output;
                                Conn.Open();
                                cmd.ExecuteNonQuery();
                                Conn.Close();
                            }
                        }
                        break;
                }
                BindGridData();
            }
        }