网学网为广大网友收集整理了,在datagrid里面添加控件。,希望对大家有所帮助!
ICollection CreateDataSource()
{
DataTable dt = new DataTable();
DataRow dr;
dt.Columns.Add(new DataColumn("主题", typeof(string)));
dt.Columns.Add(new DataColumn("发布单位", typeof(string)));
dt.Columns.Add(new DataColumn("发布时间", typeof(string)));
dt.Columns.Add(new DataColumn("删除",typeof(string)));
SqlDataReader myreader1=new dbconn().getreader("select * from bbs");
while (myreader1.Read())
{
dr = dt.NewRow();
dr[0] = "<a href=''showbbs.aspx?id=" + Convert.ToString(myreader1.GetValue(0)) + "''>" + myreader1.GetString(1) + "</a>" ;
dr[1] = myreader1.GetString(3);
dr[2] = Convert.ToString(myreader1.GetValue(4));
//HtmlInputCheckBox checkbox=new HtmlInputCheckBox();
//checkbox.ID="hello";
//checkbox.Visible=true;
dr[3]="<input type=checkbox id=''todel'' name=''todel'' value=''" + Convert.ToString(myreader1.GetValue(0)) + "''>";
dt.Rows.Add(dr);
}
有了这个,随便你是datagrid还是datalist,通吃