Add New Row to DataGrid or Repeater

  • Thread starter Thread starter rwoo_98
  • Start date Start date
R

rwoo_98

I am working on a web form that allows the user to add a new row.
Basically I query the data from a database and store it in a dataset.
I add a new row to the table in the dataset:

DataRow dr = objDataSet.Tables[0].NewRow();
objDataSet.Tables[0].Rows.Add(dr);

When I bind the data to a datagrid I see the blank row. When I bind
the data to my repeater, I don't see the blank row. Any ideas why?

Here is the html
<table border=3>
<ASP:Repeater id="MyRepeater" runat="server">
<HeaderTemplate>

<tr bgcolor="#BDC0C7">
<td width="16%" class="ary_header">Title</td>
<td width="16%" class="ary_header">ISBN</td>
<td width="16%" class="ary_header">Publication Date</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr bordercolor=#006600>
<td class="alignC"><%# DataBinder.Eval(Container.DataItem, "Title")
%></td>
<td class="alignC"><%# DataBinder.Eval(Container.DataItem, "ISBN")
%></td>
<td class="alignC"><%# DataBinder.Eval(Container.DataItem,
"PublicationDate", "{0:D}") %></td>
</tr>
</ItemTemplate>
</ASP:Repeater>
</table>
 
Do u bind repeater after adding row ? I think you specify the source for the
repeater from codebehind. Because there is no DataSource property in the
code you gave.
 
When you run the page and view the source html of it, does the datagrid
insert &nbsp; into the fields of the new row? If so, the repeater may
not display the new row because content of each data item is not
automatically generated so you basically have an empty
row<TR><TD></TD></TR>) which won't display unless there is some content
forcing it to display. Even an empty string might force it to be
displayed.
 
Back
Top