Beispiel #1
0
        protected void FillData()
        {
            //Bind List Items to Tasks List DropDown Control by id
            TasksList.DataSource     = CurrentSite.Web.Lists.TryGetList("TestList").Items;
            TasksList.DataValueField = "Title";
            TasksList.DataTextField  = "Title";
            TasksList.DataBind();

            SPListItem item = CurrentSite.Web.Lists.TryGetList("TestList").Items[0];

            ClearTextBoxes();

            //Fill textboxes
            NameText.Text = item["Task Name"].ToString();

            //If fields in tasks list is null(cause try catch is very heavy)
            if (item["Start Date"] is DateTime)
            {
                StartDate.SelectedDate = (DateTime)item["Start Date"];
            }

            if (item["Due Date"] is DateTime)
            {
                DueDate.SelectedDate = (DateTime)item["Due Date"];
            }

            if (item["% Complete"] is Double)
            {
                CompleteBox.Text = item["% Complete"].ToString();
            }
        }
    private void BindListView()
    {
        string connectionString = "Data Source=omisbi3.niunt.niu.edu;Initial Catalog = z1776252; Persist Security Info = True; User ID = z1776252; Password = Bw1243$h11";

        using (SqlConnection con = new SqlConnection(connectionString))
        {
            try
            {
                Debug.WriteLine("shopping cart before try");
                con.Open();
                Debug.WriteLine("shopping cart inside try");

                using (SqlCommand cmd = new SqlCommand("SELECT o.ord_id,s.service,o.order_date,o.order_time  from orders_table o,services_table s where s.serviceid=o.s_id and o.status='Open'", con))
                {
                    Debug.WriteLine("admin inside using try");


                    using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
                    {
                        Debug.WriteLine("shopping cart inside 2nd using");
                        DataTable dt = new DataTable();
                        Debug.WriteLine("data table is:" + dt.Rows.Count);


                        sda.Fill(dt);
                        TasksList.DataSource = dt;
                        TasksList.DataBind();

                        foreach (GridViewRow row in TasksList.Rows)
                        {
                            string       ServiceID   = (row.FindControl("Service") as Label).Text;
                            DropDownList Technicians = (row.FindControl("Technicians") as DropDownList);

                            using (SqlCommand cmd1 = new SqlCommand("SELECT T_Fname+' '+T_lname as Technician from Technician_Table where s_id=(select serviceid from services_table where service=@sev ) ", con))
                            {
                                cmd1.Parameters.AddWithValue("@sev", ServiceID.Trim());
                                using (SqlDataAdapter sda1 = new SqlDataAdapter(cmd1))
                                {
                                    System.Diagnostics.Debug.WriteLine("shopping cart inside 2nd using");
                                    using (DataSet ds = new DataSet())
                                    {
                                        sda1.Fill(ds);
                                        Technicians.DataSource     = ds;
                                        Technicians.DataTextField  = "Technician";
                                        Technicians.DataValueField = "Technician";
                                        Technicians.DataBind();
                                        Debug.WriteLine("dd list is:" + Technicians.Items.Count);
                                    }



                                    //Add Default Item in the DropDownList
                                    Technicians.Items.Insert(0, new ListItem("Please select"));

                                    //Select the Country of Customer in DropDownList
                                }
                            }
                        }
                    }
                }
            }

            catch (Exception ex)

            {
                // Display error message

                String errorMessage = ex.Message;
            }

            finally

            {
                // Close the connection

                con.Close();
            }
        }
    }