You just need to check the value entered in textbox as Admission no present in Grid records? Then just the loop through the GridViewRow records from GridView1.Rows and match the txtRegNo with each row lbl_AdNo value.
HTML
<div>
Reg No:<asp:TextBox ID="txtRegNo" runat="server"></asp:TextBox>
<asp:Button ID="btnAtten" runat="server" OnClick="btnAtten_Click" Text="Search" />
<br />
<br />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Class="table table-striped table-bordered table-hover"
OnRowDataBound="OnRowDataBound">
<Columns>
<asp:TemplateField HeaderText="Admission No">
<ItemTemplate>
<asp:Label ID="lbl_AdNo" runat="server" Text='<%#Eval("AdmissionNo") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Roll No">
<ItemTemplate>
<asp:Label ID="lbl_RollNo" runat="server" Text='<%#Eval("RollNo") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Student Name">
<ItemTemplate>
<asp:Label ID="lbl_SName" runat="server" Text='<%#Eval("SName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Father Phone">
<ItemTemplate>
<asp:Label ID="lbl_FPhone" runat="server" Text='<%#Eval("FPhone") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Status</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lbl_Status" runat="server" Text="Absent"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[4] { new DataColumn("AdmissionNo",typeof(string))
,new DataColumn("RollNo",typeof(string))
,new DataColumn("SName",typeof(string))
,new DataColumn("FPhone",typeof(string))
});
dt.Rows.Add("R-000001", "0", "FATIMA ZAHARA", "1000000000");
dt.Rows.Add("R-000002", "0", "KINZA WAJID", "2000000000");
dt.Rows.Add("R-000003", "0", "MUHAMMAD FAIZAN", "3000000000");
dt.Rows.Add("R-000004", "0", "RIYAN HAIDAR", "4000000000");
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
protected void btnAtten_Click(object sender, EventArgs e)
{
bool isRecordExists = false;
foreach (GridViewRow row in GridView1.Rows)
{
string lbl_AdNo = (row.FindControl("lbl_AdNo") as Label).Text;
if (!string.IsNullOrEmpty(txtRegNo.Text) && this.txtRegNo.Text.Trim() == lbl_AdNo)
{
txtRegNo.Text = this.txtRegNo.Text.Trim();
(row.FindControl("lbl_Status") as Label).Text = "Present";
isRecordExists = true;
}
}
if (!isRecordExists)
{
// Your alrert box message or your old code of Response.Write
//Response.Write("Reg. No. not found Try again");
}
}
Screenshot