Hi nauna,
Check this example. Now please take its reference and correct your code.
HTML
<asp:ListView ID="lvCustomers" runat="server">
<ItemTemplate>
<asp:TextBox ID="txtName" runat="server" BorderColor="#CCCCCC" Text='<%#Eval("Name") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ErrorMessage='<%#String.Format("{0} Required", Container.DataItemIndex +1)%>'
ControlToValidate="txtName" ValidationGroup="quiz" CssClass="required"></asp:RequiredFieldValidator>
<br />
<br />
</ItemTemplate>
</asp:ListView>
<asp:Button Text="Validate" runat="server" ValidationGroup="quiz" />
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.AddRange(new System.Data.DataColumn[] {
new System.Data.DataColumn("Id"), new System.Data.DataColumn("Name") });
dt.Rows.Add(1, "John Hammond");
dt.Rows.Add(2, "Mudassar Khan");
dt.Rows.Add(3, "Suzanne Mathews");
dt.Rows.Add(4, "");
lvCustomers.DataSource = dt;
lvCustomers.DataBind();
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim dt As System.Data.DataTable = New System.Data.DataTable()
dt.Columns.AddRange(New Data.DataColumn() {
New Data.DataColumn("Id"), New Data.DataColumn("Name")})
dt.Rows.Add(1, "John Hammond")
dt.Rows.Add(2, "Mudassar Khan")
dt.Rows.Add(3, "Suzanne Mathews")
dt.Rows.Add(4, "")
lvCustomers.DataSource = dt
lvCustomers.DataBind()
End If
End Sub
Screenshot