Thursday, 9 October 2014

Generate Date Time as a random no.

            int n1, s1 = 0;
            int z1 = 2;
            string m1 = "";
            string reverse1 = "";

            string i1 = System.DateTime.Now.ToShortDateString();               \\Current  Date
            string j1 = System.DateTime.Now.ToLongTimeString();                \\Current Time
            string[] a1 = i1.Split('-');
            int k1 = Convert.ToInt32(a1[0]);
            while (z1 != 0)
            {
                n1 = k1 % 10;
                m1 += (s1 * 10 + n1).ToString();
                k1 = k1 / 10;
                z1 = z1 - 1;
            }

            for (int eb = m1.Length - 1; eb > -1; eb--)                               \\ Find last 2 digit of the year
            {
                reverse1 += m1[eb];
            }
            string[] b1 = j1.Split(' ');
            string x01 = b1[0];
            string[] c01 = x01.Split(':');
            string ran = reverse1 + a1[1] + a1[2] + c01[0] + c01[1];
            string bno = "R" + ran;                                         \\ Add "R" in starting of the random no                                      

Ajax Modal Popup Example

Design Page
<div style="width:20px;float:right; position:fixed;">
                           <asp:ImageButton ID="ImageButton1" runat="server"
                               ImageUrl="~/Images/feedback1.png"  Height="120px" Width="25px" />
                           
    </div>    
Add ModalPopupExtender
  <asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
                                 TargetControlID="ImageButton1" PopupControlID="panel_feedback"
                                  DropShadow="True" BackgroundCssClass="modalBackground"
                                 CancelControlID="cross1" / >
Design Panel
<asp:Panel ID="panel_feedback" runat="server"  >
                             <center>
                             <div class="form_enquiry"><div style="float:right"><asp:ImageButton ID="cross1" runat="server" ImageUrl="~/images/cross.jpg" Width="20px" Height="20px" /></div>
                          <center><h4>FEEDBACK </h4></center>  <div>

<table>
<tr>
    <td>
        <asp:Label ID="Label4" runat="server" Text="Name"></asp:Label>
    </td>
</tr>
   <tr>
        <td>
            <asp:TextBox ID="TextBox1" runat="server" Width="221px"></asp:TextBox>
       
        </td>
   </tr>
   <tr>
    <td>
        <asp:Label ID="Label1" runat="server" Text="Email"></asp:Label>
    </td>
</tr>
   <tr>
        <td>
            <asp:TextBox ID="TextBox2" runat="server" Width="222px"></asp:TextBox>
        </td>
   </tr>
<tr>
    <td>
        <asp:Label ID="Label2" runat="server" Text="Message"></asp:Label>
    </td>
</tr>
   <tr>
        <td>
            <asp:TextBox ID="TextBox3" runat="server" Height="44px" TextMode="MultiLine"
                Width="222px" MaxLength="499" />
        </td>  </tr><tr> <td></td>
        <td style="float:right;">
 <asp:Button ID="feedButton1" runat="server" Text="Submit" onclick="feedButton1_Click" />
        </td>
   </tr>
</table></div>     </div>  </center>  </asp:Panel>
Ajax Modal Popup

Wednesday, 8 October 2014

Add text in a Gridview using RowDatabound in ASP.NET using C#

 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label l1 = (Label)e.Row.FindControl("Label5");
            if (!string.IsNullOrEmpty(l1.Text))
            {
                if (l1.Text != "300" && l1.Text != "450")
                {
                    e.Row.Cells[3].Text = "Rs. " + l1.Text + " per hour";
                    //e.Row[].Cells[3].Text = "Rs. " + l1.Text + " ";
                }
                else
                {
                    e.Row.Cells[3].Text = "Rs. " + l1.Text + " ";
                }
            }
        }
    }

Email Integration

 public void sendMail()
    {
        try
        {
            mailmsg = "Name - " + txtname.Text + "<br />Email - "+txtemail.Text+"<br />Mobile no. - " + txtmobileno.Text + "<br />" + "Message - " + txturreq.Text + "<br /><b>ABC Team</b>";
            MailMessage mail = new MailMessage();
            mail.From = new MailAddress("#####@gmail.com");
            mail.To.Add("customer1@gmail.com");
            mail.To.Add("customer2@gmail.com");
         
            mail.Subject = "Subject";
            mail.BodyEncoding = System.Text.Encoding.GetEncoding("utf-8");
            System.Net.Mail.AlternateView plainView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(System.Text.RegularExpressions.Regex.Replace(mailmsg, @"<(.|\n)*?>", string.Empty), null, "text/plain");
            System.Net.Mail.AlternateView htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(mailmsg, null, "text/html");
            mail.AlternateViews.Add(plainView);
            mail.AlternateViews.Add(htmlView);
            mail.Body = mailmsg;
            mail.IsBodyHtml = true;

            SmtpClient smtpClient = new SmtpClient();
            smtpClient.Host = "smtpout.asia.secureserver.net";
            smtpClient.Port = 25;
            smtpClient.EnableSsl = false;
            smtpClient.UseDefaultCredentials = true;
            smtpClient.Credentials = new System.Net.NetworkCredential("#####@gmail.com", "*********");
                       smtpClient.Send(mail);

        }
        catch (Exception ex)
        {
             Response.Write(ex);
        }
    }

SMS Integration in ASP.NET

HttpWebRequest myReq =(HttpWebRequest)WebRequest.Create("http://###.###.##.#/SendSMS/sendmsg.php?uname=*****&pass=*****&send=*****%20&dest=" + mobile_no. + "&msg=Dear " + "Mr./Mrs " + Name_of_user+ " Thanks! for Feedback !!! ");
             
                HttpWebResponse myResp = (HttpWebResponse)myReq.GetResponse();
                System.IO.StreamReader respStreamReader = new                                                                                  System.IO.StreamReader(myResp.GetResponseStream());
                string responseString = respStreamReader.ReadToEnd();
                respStreamReader.Close();
                myResp.Close();

Highlight values in Gridview using Rowdatabound in ASP.NET

  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label chk1 = (Label)e.Row.FindControl("Label9");
            if (!string.IsNullOrEmpty(chk1.Text))
            {
                if (chk1.Text == "Approved")
                {
                    e.Row.Cells[9].ForeColor = System.Drawing.Color.Green;
                }
                else
                {
                    e.Row.Cells[9].ForeColor = System.Drawing.Color.Red;
                }
            }
        }
}