任意在datagrid里面添加控件。

发表于:2007-06-30来源:作者:点击数: 标签:
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(stri
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,通吃  

原文转自:http://www.ltesting.net