Wednesday, 19 June 2013

display image in image control from file upload control

string path = Server.MapPath("Images/") + FileUpload1.PostedFile.FileName;
            FileUpload1.SaveAs(path);
            Image3.ImageUrl = "Images/" + FileUpload1.PostedFile.FileName;

Tuesday, 12 March 2013

how to access controls on another form c#

Form1 with 1 textbox and button
this button is for opening new form (form2)

Form2 with datagridview and button is for sending datagraidview value to textbox on Form1


On Form1
 private void button_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2(this);
            f2.Show();
        }

On Form2

 public Form2()
        {
            InitializeComponent();
        }

        private Form1 f1 = null;


        public Form2(Form callingForm)
        {
            f1 = callingForm as Form1;
            InitializeComponent();
        }

private void button_Click(object sender, EventArgs e)
        {
            this.f1.TextBox = dataGridView1.SelectedRows[0].Cells["columnname"].Value.ToString();
            this.Close();         
        }

Wednesday, 27 February 2013

how to clear all textbox in asp.net

protected void Button1_Click(object sender, EventArgs e)
        {
            ClearInputs(Page.Controls);
        }
        void ClearInputs(ControlCollection ctrls)
        {
            foreach (Control ctrl in ctrls)
            {
                if (ctrl is TextBox)
                    ((TextBox)ctrl).Text = string.Empty;
                ClearInputs(ctrl.Controls);
            }
        }

Monday, 18 February 2013

check if record already exists access



SqlConnection con = new SqlConnection(strConnString);
            SqlCommand cmdCount = new SqlCommand("select count(*) from customers where name='" + txtCustomername.Text + "'", con);
            con.Open();
            int count = (int)cmdCount.ExecuteScalar();
            if (count > 0)
            {
                lblMessage.Text = "Customer already exists";
                lblMessage.Visible = true;
            }
            else
            {
                Insert query
            }
            con.Close();

Saturday, 16 February 2013

bind dropdownlist in asp.net using dataset

 protected void BindCustomerNameddl()
        {
            con.Open();
            SqlCommand cmd = new SqlCommand("Select cid,name FROM memberLogin", con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            ddlCustomername.DataSource = ds;
            ddlCustomername.DataTextField = "name";
            ddlCustomername.DataValueField = "cid";
            ddlCustomername.DataBind();
            ddlCustomername.Items.Insert(0, new ListItem("--Select--", "0"));
            con.Close();
        }

Thursday, 31 January 2013

concatenate two strings in crystal report


Field exporer---- Formula field------create new


{Employee.employeeFirstName}+" "+{Employee.employeeMiddleName}+" "+{Employee.employeeLastName}

Tuesday, 29 January 2013

move listbox items to another listbox in c#

// all items moves from left listbox to right


int count = listBox1.Items.Count;//assigning items in listbox it into count variable
            if (count != 0)//checking the conditions
            {
                for (int i = 0; i < count; i++)
                {
                    listBox2.Items.Add(listBox1.Items[i]);
                }
            }

            listBox1.Items.Clear();//clear the listbox after transfering records.


//only selected item move to right listbox


if (listBox1.SelectedIndex > -1)
            {
                listBox2.Items.Add(listBox1.SelectedItem);//transfer records from listbox1 to Listbox2 on select records..
                listBox1.Items.Remove(listBox1.SelectedItem);

            }

//only selected item move to left listbox


if (listBox2.SelectedIndex > -1)
            {
                listBox1.Items.Add(listBox2.SelectedItem);
                listBox2.Items.Remove(listBox2.SelectedItem);
            }

// all items moves from right listbox to left


int count = listBox2.Items.Count;
            if (count != 0)
            {
                for (int i = 0; i < count; i++)
                {
                    listBox1.Items.Add(listBox2.Items[i]);
                }
            }
            listBox2.Items.Clear();