RadioButtonList邦定数据

来源:互联网 发布:淘宝直播间是什么东西 编辑:程序博客网 时间:2024/04/28 23:47


    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string name = Request.QueryString["votename"];
            Label1.Text = name;
            string id = Request.QueryString["voteid"].ToString();
            SqlConnection sqlcn = new SqlConnection("Data Source=.;Initial catalog=voet;Integrated security=true");
            sqlcn.Open();
            SqlCommand sqlcmd = new SqlCommand("select * from dbo.ItemInformation where voteId=" + id, sqlcn);
            DataTable dt = new DataTable();
            dt.Load(sqlcmd.ExecuteReader());
            RadioButtonList1.DataSource = dt;
            RadioButtonList1.DataTextField = "selectName";
            RadioButtonList1.DataValueField = "selectId";
            RadioButtonList1.DataBind();
            sqlcn.Close();

            RadioButtonList1.SelectedIndex = 0;
        }
       
       
    }

原创粉丝点击