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();


display data in listview c#


string SQL = "SELECT departmentName FROM Department";
            source.View = View.Details;

            OleDbConnection con = new OleDbConnection(connectionString);
            OleDbCommand cmd = new OleDbCommand(SQL, con);
            OleDbDataReader r = null;

            con.Open();
            r = cmd.ExecuteReader();
            for (int i = 0; i <= r.FieldCount - 1; i++)
            {
                source.Columns.Add("Column " + (i + 1).ToString(), 200, HorizontalAlignment.Left);
            }
            while (r.Read())
            {
                ListViewItem lvItem = new ListViewItem(r[0].ToString());
                for (int i = 1; i <= r.FieldCount - 1; i++)
                {
                    lvItem.SubItems.Add(r[i].ToString());
                }
                source.Items.Add(lvItem);
            }
            con.Close();

display data in listbox c#


private void displayDataInListBox()
        {
            try
            {
                OleDbConnection connection = new OleDbConnection(connectionString);
                OleDbDataAdapter da = new OleDbDataAdapter();
                connection.Open();
                OleDbDataReader Dr;
                OleDbCommand command1 = new OleDbCommand("SELECT departmentName FROM Department", connection);
                command1.ExecuteNonQuery();
                Dr = command1.ExecuteReader();
                listBox1.Items.Clear();
                while (Dr.Read())
                {

                    listBox1.Items.Add(Dr.GetString(0).ToString());

                }
                Dr.Close();
            }
            catch (OleDbException ex)
            {
                MessageBox.Show(ex.Message);
            }
          
        }