开发者

Is it possible to dynamically insert rows in an existing DataTable (No DataSource used)?

I have created a datatable with three fields namely TimeTask, TaskItem and Count (count of user) eg; {"12:30AM-01:00AM" , T1 , 3}.

        dataTable.Columns.Add("Task Time", typeof(string));
        dataTable.Columns.Add("Task", typeof(string));
        dataTable.Columns.Add("Count", typeof(int));

        dataTable.Rows.Add("12:00AM-12:15AM", "T1", 6);
        dataTable.Rows.Add("12:45AM-01:00AM", "T1", 5);                             dataTable.Rows.Add("01:00AM-01:15AM", "T1", 1);
        dataTable.Rows.Add("01:15AM-01:30AM", "T2", 4);
        dataTable.Rows.Add("01:30AM-01:45AM", "T2", 9);            
        GridView1.DataSource = dataTable;
        GridView1.DataBind();



  In this开发者_运维问答 there is no task for the TimeTask "12:15AM-12:30AM" and "12:30AM-12:45AM" yet the TimeTask should be inserted as,          

TimeTask TaskItem Count

12:00AM-12:15AM T1 6

12:15AM-12:30AM - -

12:30AM-12:45AM - -

12:45AM-01:00AM T1 5

01:00AM-01:15AM T1 1

01:15AM-01:30AM T2 4

01:30AM-01:45AM T2 9

How to chk for the missing rows? Is it possible to dynamically insert rows in an existing DataTable (No DataSource used) in this scenario.pls help.Thanks :-)


DataRow dr = dt.NewRow();
dr["Task Time"] = ....;
dr["Task"] = ....;
dr["Count"] = ....;
dt.Rows.Add(dr);

Should do the trick.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜