Important Codings

Validate Mobile number

 

if ((TextBox3.Text.StartsWith("09") == true) && (TextBox3.Text.Length == 11))

  {

  Label17.Text = "";

  }

  else if ((TextBox3.Text.StartsWith("9") == true) && (TextBox3.Text.Length == 10))

  {

  Label17.Text = "";

  }

  else

  {

  Label17.Text = "Enter valid number";

  }

  

Count down Timer

  
/Lable1.Text = 00:00:00 

  

  string[] timeArray = new string[3];

  string str1;

  static int s = 0, m = 0, h = 0;

  

protected void Timer1_Tick(object sender, EventArgs e)

  {

  str1 = Label1.Text;

  timeArray = str1.Split(':');

  s = Convert.ToInt32(timeArray[2]);

  m = Convert.ToInt32(timeArray[1]);

  h = Convert.ToInt32(timeArray[0]);

  s = s + 1;

  if ((m == min) && (h == hou))

  {

  butclick();

  }

  else

  {

  if (s != 60)

  {

  if (s <= 9)

  {

  Label1.Text = "0" + Convert.ToString(h) + ":0" + Convert.ToString(m) + ":0" + Convert.ToString(s);

  }

  else

  {

  Label1.Text = "0" + Convert.ToString(h) + ":0" + Convert.ToString(m) + ":" + Convert.ToString(s);

  }

  }

  else if ((s == 60) && (m != 60))

  {

  if (m <= 9)

  {

  s = 0;

  m = m + 1;

  Label1.Text = "0" + Convert.ToString(h) + ":0" + Convert.ToString(m) + ":0" + Convert.ToString(s);

  }

  else

  {

  s = 0;

  m = m + 1;

  Label1.Text = "0" + Convert.ToString(h) + ":0" + Convert.ToString(m) + ":0" + Convert.ToString(s);

  }

  }

  else if (m == 60)

  {

  s = 0;

  m = 0;

  h = h + 1;

  Label1.Text = "0" + Convert.ToString(h) + ":0" + Convert.ToString(m) + ":0" + Convert.ToString(s);

  }

  }

  }

  

  

How to find the controls in run time

  

  foreach (Control pa in Page.Controls)

  {

  foreach (Control ch in pa.Controls)

  {

  if (ch is RadioButtonList)

  {

//..  

  }

}

  }

  

How to generate the numbers in randomly

  

int a,b=20;

Random rdm = new Random();

a=rdm.Next(b);

  

Report in Report viewer

  

  SqlConnection con = new SqlConnection(str);

  con.Open();

  SqlDataAdapter da = new SqlDataAdapter("select * from result where day(dat)=" + d + " and month(dat)=" + m + " and year(dat)=" + y + "", con);

  DataSet ds = new DataSet();

  da.Fill(ds, "aa");

  ReportDataSource rds = new ReportDataSource("DataSet2_result", ds.Tables[0]);

  ReportViewer1.LocalReport.DataSources.Clear();

  ReportViewer1.LocalReport.DataSources.Add(rds);

  con.Close();

  

  

Report in Crystal 

  

  protected void Page_Load(object sender, EventArgs e)

  {

  indrep ds = new indrep();

  answerTableAdapter da = new answerTableAdapter();

  da.Fill(ds.answer);

  DataTable dt = ds.answer;

  ReportDocument doc = new ReportDocument();

  doc.Load(Server.MapPath("indreport.rpt"));

  doc.SetDataSource(dt);

  this.CrystalReportViewer1.ReportSource = doc;

  this.CrystalReportViewer1.DataBind();

  }