コード例 #1
0
    private void MyDataBind()
    {
        using (SqlConnection conn = new DB().GetConnection())
        {
            string     sql = "select * from [Test] where GUID = @GUID";
            SqlCommand cmd = new SqlCommand(sql, conn);
            cmd.Parameters.AddWithValue("@GUID", Request.QueryString["TestGUID"].ToString());
            conn.Open();
            SqlDataReader rd = cmd.ExecuteReader();
            if (rd.Read())
            {
                TextName.Text = rd["TestName"].ToString();
            }
            rd.Close();



            cmd.CommandText = "select * from ReportHeaderList ";
            rd = cmd.ExecuteReader();
            RC1DDL.DataSource     = rd;
            RC1DDL.DataTextField  = "Header";
            RC1DDL.DataValueField = "ID";
            RC1DDL.DataBind();
            RC1DDL.Items.Insert(0, new ListItem("", "-1"));
            rd.Close();

            cmd.CommandText = "select * from ReportHeaderList ";
            rd = cmd.ExecuteReader();
            RC2DDL.DataSource     = rd;
            RC2DDL.DataTextField  = "Header";
            RC2DDL.DataValueField = "ID";
            RC2DDL.DataBind();
            RC2DDL.Items.Insert(0, new ListItem("", "-1"));
            rd.Close();

            cmd.CommandText = "select * from ReportHeaderList ";
            rd = cmd.ExecuteReader();
            RC3DDL.DataSource     = rd;
            RC3DDL.DataTextField  = "Header";
            RC3DDL.DataValueField = "ID";
            RC3DDL.DataBind();
            RC3DDL.Items.Insert(0, new ListItem("", "-1"));
            rd.Close();

            cmd.CommandText = "select * from ReportHeaderList ";
            rd = cmd.ExecuteReader();
            RC4DDL.DataSource     = rd;
            RC4DDL.DataTextField  = "Header";
            RC4DDL.DataValueField = "ID";
            RC4DDL.DataBind();
            RC4DDL.Items.Insert(0, new ListItem("", "-1"));
            rd.Close();

            cmd.CommandText = "select * from ReportHeaderList ";
            rd = cmd.ExecuteReader();
            RC5DDL.DataSource     = rd;
            RC5DDL.DataTextField  = "Header";
            RC5DDL.DataValueField = "ID";
            RC5DDL.DataBind();
            RC5DDL.Items.Insert(0, new ListItem("", "-1"));
            rd.Close();

            cmd.CommandText = "select * from ReportHeaderList ";
            rd = cmd.ExecuteReader();
            RC6DDL.DataSource     = rd;
            RC6DDL.DataTextField  = "Header";
            RC6DDL.DataValueField = "ID";
            RC6DDL.DataBind();
            RC6DDL.Items.Insert(0, new ListItem("", "-1"));
            rd.Close();
        }
    }
コード例 #2
0
    private void DDLRead()
    {
        string headerid = "";

        string[] Header6 = new string[6];
        using (SqlConnection conn = new DB().GetConnection())
        {
            SqlCommand cmd = conn.CreateCommand();
            cmd.CommandText = "select * from [ReportHeader] where QGUID=@QGUID  order by Serial asc";
            cmd.Parameters.AddWithValue("@QGUID", Request.QueryString["TestGUID"].ToString());
            conn.Open();
            SqlDataReader rd = cmd.ExecuteReader();
            while (rd.Read())
            {
                headerid += rd["HeaderID"].ToString() + ",";
            }
            rd.Close();
        }

        string[] Header = headerid.Split(',');
        for (int j = 0; j < 6; j++)
        {
            for (int i = 0; i < Header.Length; i++)
            {
                Header6[i] = Header[i];
            }
        }

        string RF1Value = Header6[0];

        if (RC1DDL.Items.FindByValue(RF1Value) != null)
        {
            RC1DDL.ClearSelection();
            RC1DDL.Items.FindByValue(RF1Value).Selected = true;
        }

        string RF2Value = Header6[1];

        if (RC2DDL.Items.FindByValue(RF2Value) != null)
        {
            RC2DDL.ClearSelection();
            RC2DDL.Items.FindByValue(RF2Value).Selected = true;
        }

        string RF3Value = Header6[2];

        if (RC3DDL.Items.FindByValue(RF3Value) != null)
        {
            RC3DDL.ClearSelection();
            RC3DDL.Items.FindByValue(RF3Value).Selected = true;
        }

        string RF4Value = Header6[3];

        if (RC4DDL.Items.FindByValue(RF4Value) != null)
        {
            RC4DDL.ClearSelection();
            RC4DDL.Items.FindByValue(RF4Value).Selected = true;
        }

        string RF5Value = Header6[4];

        if (RC5DDL.Items.FindByValue(RF5Value) != null)
        {
            RC5DDL.ClearSelection();
            RC5DDL.Items.FindByValue(RF5Value).Selected = true;
        }

        string RF6Value = Header6[5];

        if (RC6DDL.Items.FindByValue(RF6Value) != null)
        {
            RC6DDL.ClearSelection();
            RC6DDL.Items.FindByValue(RF6Value).Selected = true;
        }
    }