Exemplo n.º 1
0
        private void BindRadioButtonList4()
        {
            List <TestClass> myList = new List <TestClass>();

            myList.Add(new TestClass("value1", "数据绑定值 1"));
            myList.Add(new TestClass("value2", "数据绑定值 2"));
            myList.Add(new TestClass("value3", "数据绑定值 3"));
            myList.Add(new TestClass("value4", "数据绑定值 4"));
            myList.Add(new TestClass("value5", "数据绑定值 5"));
            myList.Add(new TestClass("value6", "数据绑定值 6"));

            RadioButtonList4.DataTextField  = "Name";
            RadioButtonList4.DataValueField = "Id";
            RadioButtonList4.DataSource     = myList;
            RadioButtonList4.DataBind();

            RadioButtonList4.SelectedValue = "value2";
        }
Exemplo n.º 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)

        {
            DataSet ds1 = GetData2();
            for (int i = 0; i < 10; i++)
            {
                int     Qid  = int.Parse(ds1.Tables["Questions"].Rows[i][0].ToString());
                DataSet ds   = GetData1(Qid);
                int     type = int.Parse(ds1.Tables["Questions"].Rows[i][2].ToString());
                if (type == 0)
                {
                    controlArray[i] = new string[4]
                    {
                        ds.Tables["Choices"].Rows[0][0].ToString(),
                        ds.Tables["Choices"].Rows[1][0].ToString(),
                        ds.Tables["Choices"].Rows[2][0].ToString(),
                        ds.Tables["Choices"].Rows[3][0].ToString()
                    };
                }

                else
                {
                    controlArray[i] = new string[2]
                    {
                        ds.Tables["Choices"].Rows[0][0].ToString(),
                        ds.Tables["Choices"].Rows[1][0].ToString()
                    };
                }
            }

            RadioButtonList1.DataSource = controlArray[0];
            RadioButtonList1.DataBind();
            RadioButtonList2.DataSource = controlArray[1];
            RadioButtonList2.DataBind();
            RadioButtonList3.DataSource = controlArray[2];
            RadioButtonList3.DataBind();
            RadioButtonList4.DataSource = controlArray[3];
            RadioButtonList4.DataBind();
            RadioButtonList5.DataSource = controlArray[4];
            RadioButtonList5.DataBind();
            RadioButtonList6.DataSource = controlArray[5];
            RadioButtonList6.DataBind();
            RadioButtonList7.DataSource = controlArray[6];
            RadioButtonList7.DataBind();
            RadioButtonList8.DataSource = controlArray[7];
            RadioButtonList8.DataBind();
            RadioButtonList9.DataSource = controlArray[8];
            RadioButtonList9.DataBind();
            RadioButtonList10.DataSource = controlArray[9];
            RadioButtonList10.DataBind();
            Label1.Text  = ds1.Tables["Questions"].Rows[0][1].ToString();
            Label2.Text  = ds1.Tables["Questions"].Rows[1][1].ToString();
            Label3.Text  = ds1.Tables["Questions"].Rows[2][1].ToString();
            Label4.Text  = ds1.Tables["Questions"].Rows[3][1].ToString();
            Label5.Text  = ds1.Tables["Questions"].Rows[4][1].ToString();
            Label6.Text  = ds1.Tables["Questions"].Rows[5][1].ToString();
            Label7.Text  = ds1.Tables["Questions"].Rows[6][1].ToString();
            Label8.Text  = ds1.Tables["Questions"].Rows[7][1].ToString();
            Label9.Text  = ds1.Tables["Questions"].Rows[8][1].ToString();
            Label10.Text = ds1.Tables["Questions"].Rows[9][1].ToString();
        }
    }