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));
}
答案 0 :(得分:0)
从return语句中分离void方法。
p1.Controls.Add(R11));没有返回值,因此不能在return语句中用作参数。
将addrbl()中的return语句更改为:
p1.Controls.Add(rl1);
return p1;
此外,您应该返回实际的对象类型,而不仅仅是object类型的对象:
private Panel addrbl() {..}