0
protected void Page_Load(object sender, EventArgs e)
{
    using(SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS; database=employee; integrated security = SSPI"))
    {
        SqlCommand cmd = new SqlCommand("select * from emp",con);
        con.Open();
        SqlDataReader sdr = cmd.ExecuteReader();
        DataTable dt = new DataTable();
        dt.Columns.Add("ID");
        dt.Columns.Add("Name");
        dt.Columns.Add("Option");
        while (sdr.Read())
        {
           DataRow dr = dt.NewRow();
           dr["ID"] = sdr["uid"];
           dr["Name"] = sdr["uname"];
           dr["Option"] = addrbl();
           dt.Rows.Add(dr);


        }
        GridView1.DataSource = dt;
        GridView1.DataBind();

    }
}

private object addrbl()
{
    Panel p1 = new Panel();

    RadioButtonList rl1 = new RadioButtonList();
    rl1.Items.Add(new ListItem("yes","1"));
    rl1.Items.Add(new ListItem("no","0"));
    return(p1.Controls.Add(rl1));
}
4

1 回答 1

0

将 void 方法与 return 语句分开。

p1.Controls.Add(r11)); 没有返回值,因此不能用作 return 语句中的参数。

将 addrbl() 中的 return 语句更改为:

p1.Controls.Add(rl1);
return p1;

此外,您应该返回实际的对象类型,而不仅仅是对象类型的对象:

private Panel addrbl() {..}
于 2013-02-06T19:01:08.630 回答