I have a code:
foreach (GridViewRow dr in gvCategories.Rows)<br/>
{
<br/>
if (dr.Cells[0].Text == txtEnterCategory.Text.Trim())<br/>
<br/>
isError=true;
<br/>
<br/>
}
Debugging: dr.Cells[0].Text
is always ""
, even there are records. How to use a loop to check each row to find if a record exists in the gridview not using sql?
More code:
in .ascx:
<.Columns> TemplateField HeaderText="Category Name" SortExpression="Category"> ' OnTextChanged="TextBox_TextChanged"> ' OnTextChanged="TextBox_TextChanged">
</asp:TemplateField>
<asp:TemplateField HeaderText="In Footer?" SortExpression="ShowInFooter">
<ItemTemplate>
<asp:Label ID="lblShowInFooter" runat="server"
Text='<%# (bool)Eval("ShowInFooter") ? "Yes" : "No" %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:CheckBox ID="lblShowInFooter" runat="server"
Checked='<%# (bool)Eval("ShowInFooter")%>'>
</asp:CheckBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowCancelButton="true" ShowDeleteButton="true" ShowEditButton="true" CausesValidation="false" ItemStyle-CssClass="commandfield" />
</Columns>
in ascx.cs:
bool isError = false;
foreach (GridViewRow dr in gvCategories.Rows)
{
if (dr.Cells[0].Text == txtEnterCategory.Text.Trim())
{
lblErrorMessage.Text = "This category already exits. Please enter a new category!";
lblErrorMessage.Visible = true;
isError=true;
}
}