Connecting Tech Pros Worldwide Help | Site Map

How to Add an new row in DataGrid programmatically?

Nicky
Guest
 
Posts: n/a
#1: Nov 19 '05
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!
DotNetJerome
Guest
 
Posts: n/a
#2: Nov 19 '05

re: How to Add an new row in DataGrid programmatically?


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:
[color=blue]
> 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![/color]
Closed Thread