Posts

Final Project

Image
Registration form project   CODING- using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Configuration; public partial class RegPage : System.Web.UI.Page {     SqlConnection cn;     SqlCommand cm;     SqlDataReader dr;     FinalClass fc = new FinalClass();     protected void Page_Load(object sender, EventArgs e)     {         if (!IsPostBack)         {             statedisplay();         }     }     protected void connect()     {         string s = ConfigurationManager.AppSettings["Ch_Db"];         cn = new SqlConnection(s);         cn.Open();          }     protected void statedisplay...

Checking File Extension

                   string ext = System.IO.Path.GetExtension(FileUpload1.FileName);         if (ext != ".jpg" && ext != ".jpeg")         {             Response.Write("accept only jpg file");         }         else         {              FileUpload1.SaveAs(Server.MapPath("~") + "//upload//" + FileUpload1.FileName);             Image1.ImageUrl = "~/upload/" +  FileUpload1.FileName;                 }

Export GridView to Excel

            string attachment = "attachment; filename=registration.xls";         Response.ClearContent();         Response.AddHeader("content-disposition", attachment);         Response.ContentType = "application/ms-excel";         StringWriter sw = new StringWriter();         HtmlTextWriter htw = new HtmlTextWriter(sw);         HttpContext.Current.Response.Write("<br>");         HtmlForm frm = new HtmlForm();         GridView1.Parent.Controls.Add(frm);         frm.Attributes["runat"] = "serve";         frm.Controls.Add(GridView1);         frm.RenderControl(htw);         Response.Write(sw.ToString());         Response.End();

Dynamic Data Grid View

protected void Button1_Click(object sender, EventArgs e) { DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[3]  { // typeof() is used for dynamic data type allocation new Column("id",typeof(int)), new Column("Name",typeof(string)), new Column("City",typeof(string)) }); dt.Rows.Add(1,"Chitransh","Jabalpur"); dt.Rows.Add(2,"Shashank","Bhopal"); dt.Rows.Add(3,"Ananya","Delhi"); GridView1.Datasource = dt; GridView1.DataBind(); }

Select the RadioButtonList Item Using User Input

  CODE:- RadioButtonList1.Items.FindByText(dr["column_name"].ToString()).Selected== true; --------------------------------------------------------------------------------------------------------------------- Implementation:-   protected void Button3_Click(object sender, EventArgs e)     {         myclass m1 = new myclass();         string cs = m1.connection(); // calling function inside a class          cn = new SqlConnection(cs);         cn.Open();         string q = "select * from chitransh_table where name='"+TextBox5.Text+"'";         cm = new SqlCommand(q, cn);         dr = cm.ExecuteReader();         if (dr.Read())         {             RadioButtonList1.Items.FindByText(dr["city"].ToString()).Selected = true;         }   ...

Break the Control Refreshment

  Example:- <form>   <asp:ScriptManager> </asp:ScriptManager> <asp:UpdatePanel> <ContentTemplate> <asp:DropDownList>// place any Drop down list  <asp:ListItem> //Items </asp:ListItem> </asp: DropDownList > </ContentTemplate> </asp:UpdatePanel> </form>

Email Programming

  Email-  It is used to send a message electronically. Types of email- 1. Simple mailing(Gmail,Yahoo) Open to all. 2. Domain Based Email(WebMail) Company uses this kind of mail. Email programming in dot net- Steps-  1. Include library- using System.Net.Mail; 2. Objects are created- i. smtpClient ii. MailMessage  3. Format of email- html  Coding- //Two parameters - domain name and port number of email. smtpClient sm = new smtpClient("student-cell.com",25);  // here we have to give the credentials email id and password  sm.Credentials = new System.Net.NetworkCredential("contact@student-cell.com","password"); //this method will deliver your email to network sm.DeliveryMethod = smtpDeliveryMethod.Network;  // Mail Message object is created passing the email id and the control where recipient id will be  MailMessage mm = new MailMessage("contact@student-cell.com",TextBox1.Text); mm.Subject = "Hey buddy its me" + TextBox1.Text; mm.Body = ...