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));
}
问问题
1225 次