Please refer this example
HTML
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<th>
Id
</th>
<th>
Name
</th>
<th>
Country
</th>
<th>
</th>
<th>
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label ID="lblId" Text='<%# Eval("Id") %>' runat="server" />
</td>
<td>
<asp:Label ID="lblName" Text='<%# Eval("Name") %>' runat="server" />
</td>
<td>
<asp:Label ID="lblCountry" Text='<%# Eval("Country") %>' runat="server" />
</td>
<td>
<asp:Button ID="btnSave" Text="Save" CommandName="Save" OnClick="SaveOrUpdate" runat="server" />
</td>
<td>
<asp:Button ID="btnUpdate" Text="Update" CommandName="Update" OnClick="SaveOrUpdate"
runat="server" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
Namespace
using System.Data;
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Id", typeof(int)),
new DataColumn("Name", typeof(string)),
new DataColumn("Country",typeof(string)) });
dt.Rows.Add(1, "John Hammond", "United States");
dt.Rows.Add(2, "Mudassar Khan", "India");
dt.Rows.Add(3, "Suzanne Mathews", "France");
dt.Rows.Add(4, "Robert Schidner", "Russia");
Repeater1.DataSource = dt;
Repeater1.DataBind();
}
}
protected void SaveOrUpdate(object sender, EventArgs e)
{
Button saveOrUpdate = (sender as Button);
RepeaterItem item = saveOrUpdate.NamingContainer as RepeaterItem;
string id = (item.FindControl("lblId") as Label).Text;
string name = (item.FindControl("lblName") as Label).Text;
string country = (item.FindControl("lblCountry") as Label).Text;
switch (saveOrUpdate.CommandName)
{
case "Update":
this.Update(id, name, country);
break;
case "Save":
this.Save(id, name, country);
break;
}
}
private void Update(string id, string name, string country)
{
//Write code here to Update the record
}
private void Save(string id, string name, string country)
{
//Write code here to Save the record
}