Repeater dynamically Add rows

Source: Internet
Author: User

<Table class = "Table-striped table-bordered table-Hover">
<Asp: repeater id = "rp_list" runat = "server" onitemcommand = "rp_list_itemcommand">
<Headertemplate>
<Thead>
<Tr>
<TH>
ID
</Th>
<TH>
Chinese content
</Th>
<TH>
English Content
</Th>
<TH>
Upload sound <% -- (required when adding <SPAN class = "text-danger"> </span>) -- %>
</Th>
<TH width = "80px">
Avatar
</Th>
<TH width = "80px">
Dialog sorting
</Th>
<TH width = "80px">
Max time
</Th>
<TH width = "80px">
Sound time
</Th>
<TH>
Operation
</Th>
</Tr>
</Thead>
</Headertemplate>
<Itemtemplate>
<Tr>
<TD>
<% # Container. itemindex + 1%>
<Asp: hiddenfield id = "hidid" runat = "server" value = '<% # eval ("ID") %>'/>
</TD>

<TD>
<Asp: textbox id = "txtcountentzh" runat = "server" text = '<% # eval ("contentzh ") %> 'class = "form-control"> </ASP: textbox>
</TD>
<TD>
<Asp: textbox id = "txtcountenten" runat = "server" text = '<% # eval ("contenten ") %> 'class = "form-control"> </ASP: textbox>
</TD>
<TD>
<% -- <Asp: fileupload id = "fileupload" runat = "server" cssclass = "form-control"/> -- %>
<Asp: Label id = "lblsound" runat = "server" text = '<% # eval ("ishave") %>'> </ASP: Label>
</TD>
<TD>
<Asp: textbox id = "txtphoto" runat = "server" class = "form-control" text = '<% # eval ("photo ") %> '> </ASP: textbox>
</TD>
<TD>
<Asp: textbox id = "txtorder" runat = "server" class = "form-control" text = '<% # eval ("orderby ") %> '> </ASP: textbox>
</TD>
<TD>
<Asp: textbox id = "txtmaxsecond" runat = "server" class = "form-control" text = '<% # eval ("maxsecond ") %> '> </ASP: textbox>

</TD>
<TD>
<Asp: textbox id = "txtsoundsize" runat = "server" class = "form-control" text = '<% # eval ("soundsize ") %> '> </ASP: textbox>
</TD>
<TD>
<% -- <A href = "duihuadelete. aspx? Id = <% # eval ("ID ") %> & page = <% = currentpage %> & pianzhangid = <% = pzid %> "class =" BTN-danger "onclick =" Return confirm ('whether to delete the data ') "> Delete </a> -- %>
<% -- <A href = "duihuaedit. aspx? Id = <% # eval ("ID") %> & pianzhangid = <% = pzid %> "class =" BTN-primary "> edit </a>
<A href = "dui1_idetail. aspx? Id = <% # eval ("ID") %> "class =" BTN-default BTN-primary "Title =" details "> details </a> -- %>
<Asp: linkbutton id = "lbtndelete" runat = "server" cssclass = "BTN-danger" onclientclick = 'Return confirm ("are you sure you want to delete? ") 'Commandname =" Del "commandargument = '<% # eval (" ID ") %>'> Delete </ASP: linkbutton>
<Asp: linkbutton id = "lbtnedit" runat = "server" cssclass = "BTN-Default" commandname = "edit" commandargument = '<% # eval ("ID ") %> '> edit </ASP: linkbutton>
</TD>
</Itemtemplate>
<Footertemplate>
<Tr id = "tr1" runat = "server" visible = "<% # rp_list.items.count = 0%>">
<TD colspan = "9" class = "indent15">
No matching information found
</TD>
</Tr>
</Footertemplate>
</ASP: repeater>
</Table>

Background code:

Protected void btnaddnewrow_click (Object sender, eventargs E)
{

// First, restore the data source

Datatable dt = definedatatableschema (hfrptcolumns. value );

Foreach (repeateritem item in rp_list.items)

{

Datarow newrow = DT. newrow ();

Newrow ["ID"] = (hiddenfield) item. findcontrol ("hidid"). value;

Newrow ["contentzh"] = (textbox) item. findcontrol ("txtcountentzh"). text;

Newrow ["contenten"] = (textbox) item. findcontrol ("txtcountenten"). text;

Newrow ["photo"] = (textbox) item. findcontrol ("txtphoto"). text;

Newrow ["orderby"] = (textbox) item. findcontrol ("txtorder"). text;

Newrow ["maxsecond"] = (textbox) item. findcontrol ("txtmaxsecond"). text;

Newrow ["ishave"] = (Label) item. findcontrol ("lblsound"). text;

Newrow ["soundsize"] = (textbox) item. findcontrol ("txtsoundsize"). text;

DT. Rows. Add (newrow );

}

// Add a row

Datarow ROW = DT. newrow ();

Row ["contentzh"] = "";

Row ["contenten"] = "";

Row ["photo"] = "";

Row ["orderby"] = "0 ";

Row ["maxsecond"] = "1 ";

Row ["ishave"] = "not uploaded ";

Row ["soundsize"] = "1 ";

DT. Rows. Add (ROW );

Rp_list.datasource = DT;

Rp_list.databind ();

}

/// <Summary>
/// Define the schema of the data source datatable Based on the column name corresponding to the repeater
/// </Summary>
/// <Param name = "columns"> column name </param>
/// <Returns> </returns>
Public datatable definedatatableschema (string columns)
{
Datatable dt = new datatable ();
String [] columnsary = columns. Split (',');
Foreach (string STR in columnsary)
{
DT. Columns. Add (STR );
}
Return DT;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.