How to Add an new row in DataGrid programmatically?

Discussion in 'ASP .Net' started by =?Utf-8?B?Tmlja3k=?=, Feb 26, 2005.

  1. hi, all

    I have a asp.net page, and there is a DataGrid in it. I want show it like
    Header: ID, StartTime, EndTime.......
    1 12:20 12:40
    This is the job which is ........
    2 14:30 14:45
    This is the second job ........
    Here, each item contains two row.What is the best solution for this? Or I
    should not use DataGrid for it?
    What I did is response ItemDateBound message, for each item, add an new item
    to display the description "This is the job...."
    private void ADDataGrid_ItemDataBound(object sender,
    System.Web.UI.WebControls.DataGridItemEventArgs e)
    {

    if(e.Item.ItemType == ListItemType.Item)
    {
    DataGridItem dataGridItem = new DataGridItem(0,0,ListItemType.Item);

    TableCell tableCell = new TableCell();
    tableCell.ColumnSpan = 8;
    tableCell.Text = "This is the job which is... ";
    dataGridItem.Cells.Add(tableCell);
    ADDataGrid.Controls[0].Controls.Add(dataGridItem);
    }
    }
    But it did not do anything for me. Why?
    Thanks for any reply!
     
    =?Utf-8?B?Tmlja3k=?=, Feb 26, 2005
    #1
    1. Advertising

  2. Hi Nicky,

    You can't do so with datagrid....but you can do it with DataRepeater
    control, even with datalist too.

    Cheers,

    Jerome. M

    "Nicky" wrote:

    > hi, all
    >
    > I have a asp.net page, and there is a DataGrid in it. I want show it like
    > Header: ID, StartTime, EndTime.......
    > 1 12:20 12:40
    > This is the job which is ........
    > 2 14:30 14:45
    > This is the second job ........
    > Here, each item contains two row.What is the best solution for this? Or I
    > should not use DataGrid for it?
    > What I did is response ItemDateBound message, for each item, add an new item
    > to display the description "This is the job...."
    > private void ADDataGrid_ItemDataBound(object sender,
    > System.Web.UI.WebControls.DataGridItemEventArgs e)
    > {
    >
    > if(e.Item.ItemType == ListItemType.Item)
    > {
    > DataGridItem dataGridItem = new DataGridItem(0,0,ListItemType.Item);
    >
    > TableCell tableCell = new TableCell();
    > tableCell.ColumnSpan = 8;
    > tableCell.Text = "This is the job which is... ";
    > dataGridItem.Cells.Add(tableCell);
    > ADDataGrid.Controls[0].Controls.Add(dataGridItem);
    > }
    > }
    > But it did not do anything for me. Why?
    > Thanks for any reply!
     
    =?Utf-8?B?RG90TmV0SmVyb21l?=, Feb 26, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?U3VyZXNo?=
    Replies:
    1
    Views:
    469
    Saravana
    Nov 22, 2004
  2. Replies:
    0
    Views:
    364
  3. Replies:
    0
    Views:
    424
  4. Chris

    Add GridView Row Programmatically

    Chris, Apr 20, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    6,164
    Chris
    Apr 20, 2006
  5. Paul
    Replies:
    1
    Views:
    2,286
    Hermit Dave
    Jul 11, 2008
Loading...

Share This Page