Wednesday, December 4, 2013

numericUpDown

private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
            label4.Text = numericUpDown1.Value.ToString();

        }

Swap Panels

  private void Form1_Load(object sender, EventArgs e)
        {
            panel2.Visible = false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (panel1.Visible == true)
            {
                panel2.Visible = true;
                panel1.Visible = false;

            }
            else
            {
                panel1.Visible = true;
                panel2.Visible = false;
            }
            

        }

selectio of two radio buttons in windows forms

1. take two radio buttons
And two checkboxes
If radiobutton1 pressed then automatically it checks the first checkbox and enters that value to textbox
In the same way second also. If two radio buttons checked then place two values in textbox

Code it in windows forms

use pannels


private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
          
            if (radioButton1.Checked == true)
            {
                checkBox1.Checked = true;
                textBox1.Text += checkBox1.Text;
            }
            else
            {
                checkBox1.Checked = false;
            }
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
        
            if (radioButton2.Checked == true)
            {
                checkBox2.Checked = true;
                textBox1.Text += checkBox2.Text;
            }
            else
            {
                checkBox2.Checked = false;
            }
        }

Thursday, November 28, 2013

fill drop down list from database

 private void Form1_Load(object sender, EventArgs e)
        {
            con.Open();

            SqlDataAdapter da = new SqlDataAdapter("select name from sample ", con);
            DataTable dt = new DataTable();
            da.Fill(dt);
            comboBox1.DataSource = dt ;
            comboBox1.ValueMember = "name";
            comboBox1.DisplayMember = "name";
            con.Close();

        }

retrieving data from database to lables

  private void button3_Click(object sender, EventArgs e)
        {
            con.Open();
            SqlCommand cmd9 = new SqlCommand("select * from sample", con);
            SqlDataReader dr = cmd9.ExecuteReader();
            while (dr.Read())
            {
                textBox3.Text = dr["name"].ToString();
                textBox4.Text = dr["email"].ToString();
            }
        }

Monday, November 25, 2013

Export Grid View to excel and word in asp

//Before pasting this code, In design you have one grid view(ex:gvdetails) and  two buttons(ex :btnWord, btnExcel)
using System;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
public override void VerifyRenderingInServerForm(Control control)
{
/* Verifies that the control is rendered */
}

protected void btnWord_Click(object sender, ImageClickEventArgs e)
{
gvdetails.AllowPaging = false;
gvdetails.DataBind();
Response.ClearContent();
Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "Customers.doc"));
Response.Charset = "";
Response.ContentType = "application/ms-word";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gvdetails.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
/// <summary>
/// This Event is used to export gridview data to Excel
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnExcel_Click(object sender, ImageClickEventArgs e)
{
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "Customers.xls"));
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gvdetails.AllowPaging = false;
gvdetails.DataBind();
//Change the Header Row back to white color
gvdetails.HeaderRow.Style.Add("background-color", "#FFFFFF");
//Applying stlye to gridview header cells
for (int i = 0; i < gvdetails.HeaderRow.Cells.Count; i++)
{
gvdetails.HeaderRow.Cells[i].Style.Add("background-color", "#507CD1");
}
int j = 1;
//This loop is used to apply stlye to cells based on particular row
foreach (GridViewRow gvrow in gvdetails.Rows)
{
gvrow.BackColor = Color.White;
if (j <= gvdetails.Rows.Count)
{
if (j % 2 != 0)
{
for (int k = 0; k < gvrow.Cells.Count; k++)
{
gvrow.Cells[k].Style.Add("background-color", "#EFF3FB");
}
}
}
j++;
}
gvdetails.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
   
 
}

Friday, November 8, 2013

slidshow

 Random r = new Random();
        int a = r.Next(1, 5);
        Image1.ImageUrl = "image/" + a.ToString() + ".jpg";



use a timer
and script manager
and place code in formload