Example #1
0
        protected void btnClear_Click(object sender, EventArgs e)
        {
            DataTable ds = new DataTable();

            ds = null;
            GridViewSearches.DataSource = ds;
            GridViewSearches.DataBind();
            lblMessage.Text = string.Empty;
        }
Example #2
0
        private void ExpenseSearch()
        {
            SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["Expenses"].ConnectionString);

            cn.Open();
            SqlCommand cmdGetExpenses = new SqlCommand("spResourceSearch", cn);

            cmdGetExpenses.CommandType = CommandType.StoredProcedure;
            DateTime startDate = Convert.ToDateTime(String.IsNullOrEmpty(tbStartDate.Text) ? null : tbStartDate.Text);
            string   start     = String.Format("{0:MM/dd/yyyy}", startDate);
            DateTime endDate   = Convert.ToDateTime(String.IsNullOrEmpty(tbEndDate.Text) ? null : tbEndDate.Text);;
            string   end       = String.Format("{0:MM/dd/yyyy}", endDate);
            string   resource  = tbResourceTypeDescription.Text;

            switch (resource)
            {
            case "Electricity":
                ResourceTypeId = 1;
                break;

            case "Telephone":
                ResourceTypeId = 2;
                break;

            case "Water":
                ResourceTypeId = 3;
                break;

            case "":
                ResourceTypeId = 0;
                break;
            }
            cmdGetExpenses.Parameters.AddWithValue("ResourceTypeId", ResourceTypeId);

            cmdGetExpenses.Parameters.AddWithValue("StartDate", String.IsNullOrEmpty(tbStartDate.Text) ? (object)DBNull.Value : start);
            cmdGetExpenses.Parameters.AddWithValue("EndDate", String.IsNullOrEmpty(tbEndDate.Text) ? (object)DBNull.Value : end);

            GridViewSearches.Visible = true;
            SqlDataReader rdrS = cmdGetExpenses.ExecuteReader();

            GridViewSearches.DataSource = rdrS;

            GridViewSearches.DataBind();

            cn.Close();
        }