Hi JennyD6856,
Check this example. Now please take its reference and correct your code.
HTML
Name:
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
<br />
<br />
Country
<asp:TextBox ID="txtCountry" runat="server"></asp:TextBox>
<asp:Button ID="btnShowRepeater" runat="server" Text="Submit" OnClick="btnShowRepeater_Click" />
<br />
<asp:Repeater ID="reptView" runat="server">
<HeaderTemplate>
<table>
<tr>
<th style="width: 15px">
CustomerId
</th>
<th style="width: 15px">
Name
</th>
<th>
Country
</th>
<th>
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label ID="lblId" Text='<%# Eval("CustomerId") %>' runat="server" />
</td>
<td>
<asp:Label ID="lblName" Text='<%# Eval("Name") %>' runat="server" />
</td>
<td>
<asp:Label ID="ucCountry" Text='<%# Eval("Country") %>' runat="server" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
Namespaces
C#
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
VB.Net
Imports System.Data.SqlClient
Imports System.Data
Code
C#
private void Bind()
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConString"].ConnectionString);
SqlCommand cmd = new SqlCommand("SELECT * FROM CustomerTest", conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
reptView.DataSource = dt;
reptView.DataBind();
}
protected void btnShowRepeater_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConString"].ConnectionString);
SqlCommand cmd = new SqlCommand("INSERT INTO CustomerTest(Name,Country) VALUES(@Name,@Country)", conn);
cmd.Parameters.AddWithValue("@Name", txtName.Text);
cmd.Parameters.AddWithValue("@Country", txtCountry.Text);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
this.Bind();
}
Vb.Net
Private Sub Bind()
Dim conn As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("ConString").ConnectionString)
Dim cmd As SqlCommand = New SqlCommand("SELECT * FROM CustomerTest", conn)
Dim da As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim dt As DataTable = New DataTable()
da.Fill(dt)
reptView.DataSource = dt
reptView.DataBind()
End Sub
Protected Sub btnShowRepeater_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim conn As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("ConString").ConnectionString)
Dim cmd As SqlCommand = New SqlCommand("INSERT INTO CustomerTest(Name,Country) VALUES(@Name,@Country)", conn)
cmd.Parameters.AddWithValue("@Name", txtName.Text)
cmd.Parameters.AddWithValue("@Country", txtCountry.Text)
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
Me.Bind()
End Sub
Screenshot