developer155
Programmer
Hi I have the below GridView and I am trying to iterate through all the name fields in it in AJAX function.
Here is the gridview
<asp:gridview id="CustomLists"
allowpaging="false"
runat="server"
CssClass="lists"
HeaderStyle-Wrap="false"
AutoGenerateColumns ="false"
OnRowDataBound="CustomLists_RowDataBound">
<HeaderStyle CssClass="header" ></HeaderStyle>
<Columns>
<asp:BoundField ReadOnly="True" DataField="customListID" SortExpression="customListID" HeaderText="id" HeaderStyle-CssClass="id">
<ItemStyle CssClass="id" />
</asp:BoundField>
<asp:BoundField ReadOnly="True" DataField="name" SortExpression="name" HeaderText="list name" HeaderStyle-CssClass="name">
<ItemStyle CssClass="name" />
</asp:BoundField>
And here is the code I wrote to iterate through it(crashes):
foreach (GridViewRow row in CustomLists.Rows)
{
DataRowView drv = (DataRowView)row.DataItem;
if (drv["name"].ToString() == "some value")
return "false";
}
Basically I am interested DataField="name" column. I need to examine each one and compare it to some value. PLease let me know what I am doing wrong while iterating
thanks
Here is the gridview
<asp:gridview id="CustomLists"
allowpaging="false"
runat="server"
CssClass="lists"
HeaderStyle-Wrap="false"
AutoGenerateColumns ="false"
OnRowDataBound="CustomLists_RowDataBound">
<HeaderStyle CssClass="header" ></HeaderStyle>
<Columns>
<asp:BoundField ReadOnly="True" DataField="customListID" SortExpression="customListID" HeaderText="id" HeaderStyle-CssClass="id">
<ItemStyle CssClass="id" />
</asp:BoundField>
<asp:BoundField ReadOnly="True" DataField="name" SortExpression="name" HeaderText="list name" HeaderStyle-CssClass="name">
<ItemStyle CssClass="name" />
</asp:BoundField>
And here is the code I wrote to iterate through it(crashes):
foreach (GridViewRow row in CustomLists.Rows)
{
DataRowView drv = (DataRowView)row.DataItem;
if (drv["name"].ToString() == "some value")
return "false";
}
Basically I am interested DataField="name" column. I need to examine each one and compare it to some value. PLease let me know what I am doing wrong while iterating
thanks