i am using gridview to validate the columns. that is if the 'case attended' column has the value 'attended' then it is in green color or 'not attended' means orange color otherwise it is in red color. like wise for 'gender' column and 'prescription' column. i am using the same technique for 2 pages. 1st page is working correctly but 2nd page is not working correctly. i really dont understand what is happening. would you rectify my mistake?. i had sent you my screenshot and my workin and not wroking code for your reference.
Not wroking Code
<asp:GridView ID="GridViewsel" HeaderStyle-BackColor="#333333" gridline="none" HeaderStyle-ForeColor="White" CssClass="gridviewtable"
HeaderStyle-Height="40px" RowStyle-Height="40px" AlternatingRowStyle-BackColor="#F5F5F5" runat="server" AutoGenerateColumns="False"
OnRowDataBound="GridViewsel_RowDataBound" EnableViewState="true" DataKeyNames="RegistrationID">
<Columns>
<asp:TemplateField HeaderText="S.No" ItemStyle-HorizontalAlign="Center" >
<ItemTemplate>
<%#Container.DataItemIndex+1 %>
</ItemTemplate>
<ItemStyle Width="32px" />
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="Reg.ID" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="50">
<ItemTemplate>
<asp:Label ID="lblregid" runat="server" Text='<%# Eval("RegistrationID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Patient ID" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="70">
<ItemTemplate>
<asp:Label ID="lblpatid" runat="server" Text='<%# Eval("Patient_ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Patient Name" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="100">
<ItemTemplate>
<asp:Label ID="lblpName" runat="server" Text='<%# Eval("P_Name") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtpName" runat="server" Text='<%# Eval("P_Name") %>' Width="100"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Gender" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="50">
<ItemTemplate>
<asp:Label ID="lblgen" runat="server" Text='<%# Eval("Gender") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtgen" runat="server" Text='<%# Eval("Gender") %>' Width="50"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Age" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="30">
<ItemTemplate>
<asp:Label ID="lblage" runat="server" Text='<%# Eval("age") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtage" runat="server" Text='<%# Eval("age") %>' Width="50"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Address" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="100">
<ItemTemplate>
<asp:Label ID="lbladdr" runat="server" Text='<%# Eval("address") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtaddr" runat="server" Text='<%# Eval("address") %>' Width="100"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Mobile" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="100">
<ItemTemplate>
<asp:Label ID="lblmob" runat="server" Text='<%# Eval("mobile") +" / "+ Eval("altmobile")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtmob" runat="server" Text='<%# Eval("mobile") %>' Width="100"></asp:TextBox>
<asp:TextBox ID="txtaltmob" runat="server" Text='<%# Eval("altmobile") %>' Width="100"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="RefDoctor" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="100">
<ItemTemplate>
<asp:Label ID="lblrefdoc" runat="server" Text='<%# Eval("RefDoctor") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtrefdoc" runat="server" Text='<%# Eval("RefDoctor") %>' Width="100"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Appointment Date" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="150">
<ItemTemplate>
<asp:Label ID="lbldate" runat="server" Text='<%# Eval("AppDated") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtdate" runat="server" Text='<%# Eval("AppDated") %>' Width="100"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Case Status" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="100">
<ItemTemplate>
<asp:Label ID="lblcseatt" runat="server" Text='<%# Eval("CaseAtten") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Payment">
<ItemTemplate>
<asp:LinkButton ID="lnkViewDetails" runat="server" CssClass="btn-sm" CommandArgument='<%# Eval("RegistrationID")%>' OnClick="ViewDetails" Text="Payment" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Payment History">
<ItemTemplate>
<asp:LinkButton ID="lnkpayhistory" Text="Payment History" CssClass="btn-sm" OnClick="lnkpayhistory_Click" runat="server"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Actions">
<ItemTemplate>
<asp:LinkButton ID="lnkeditnew" OnClick="lnkeditnew_Click" ToolTip="Edit" CssClass=" editimg dis dis_btn dis_large" runat="server"> </asp:LinkButton>
<asp:LinkButton ID="lnkcanapp" Text="" ToolTip="Cancel Appointment" CssClass="delimg dis dis_btn dis_large" OnClick="lnkcanapp_Click" runat="server">C</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
protected void GridViewsel_RowDataBound(object sender, GridViewRowEventArgs e)
{
TableCell cell = e.Row.Cells[10];
TableCell cell4 = e.Row.Cells[4];
TableCell cell11 = e.Row.Cells[11];
string y = "Attended";
string z = "Cancelled";
string a = "Male";
string quantity = (cell.Text.ToString());
string gen = (cell4.Text.ToString());
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (quantity == y)
{
cell11.Enabled = true;
}
else
{
cell11.Enabled = false;
}
}
int cntYes = 0, cntNo = 0, cntcan = 0;
foreach (GridViewRow row in GridViewsel.Rows)
{
if (row.Cells[10].Text == "Attended")
{
cntYes++;
}
else if (row.Cells[10].Text == "Not Attended")
{
cntNo++;
}
else
{
cntcan++;
}
}
lblpen.Text = cntNo.ToString();
lblcomp.Text = cntYes.ToString();
lblcan.Text = cntcan.ToString();
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (quantity == y)
{
cell.ForeColor = Color.Green;
}
else if (quantity == z)
{
cell.ForeColor = Color.Red;
}
else
{
cell.ForeColor = Color.Orange;
}
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (gen == a)
{
cell4.ForeColor = Color.Green;
}
else
{
cell4.ForeColor = Color.Red;
}
}
}