below is gridview code
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lbleno" Text='<%#Eval("eno") %>' runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="txtename" Text='<%#Eval("ename") %>' runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="txtename1" Text='<%#Eval("ename") %>' runat="server"></asp:TextBox>
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="ename,ename1 must match"
OnServerValidate="CustomValidator1_ServerValidate" ValidateEmptyText="true" ValidationGroup="txt"></asp:CustomValidator>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lblsal" Text='<%#Eval("salary") %>' runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btnsubmit" runat="server" Text="Submit" ValidationGroup="txt" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
.cs page code
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlConnection conn = new SqlConnection(your connection string);
SqlDataAdapter da = new SqlDataAdapter("select * from tablename", conn);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
}
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
CustomValidator cv=(CustomValidator)source;
GridViewRow gvr = (GridViewRow)cv.NamingContainer;
TextBox txt1 = (TextBox)gvr.FindControl("txtename");
TextBox txt2= (TextBox)gvr.FindControl("txtename1");
if(txt1.Text==txt2.Text)
{
args.IsValid=true;
}
else
args.IsValid=false;
}
i have executed this as ana example you can change it according to your purpose,
condition also you can use your required condition