Click here to Skip to main content
15,918,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have a grid view with unbound checkbos and BoundFields how do I write the query to count all the rows where
checkbox (cbx)==checked and boundfield "Tytle"=="household"
the gridvew looks like:
XML
<asp:GridView ID="gvPerson" runat="server" AutoGenerateColumns="False"
    DataKeyNames="EmployeeID" DataSourceID="SqlDataSource1" >
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
        <asp:CheckBox id="cbx" runat="server"></asp:CheckBox>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="EmployeeID" HeaderText="EmployeeID"
            InsertVisible="False" ReadOnly="True" SortExpression="EmployeeID" />
        <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
        <asp:BoundField DataField="Gender" HeaderText="Gender"
            SortExpression="Gender" />
    </Columns>
Posted
Updated 17-Oct-10 2:07am
v2

If it were me, I'd handle the checkbox click event, and set a bool IsChecked property in the actual object bound to the grid, and then you could simply use Linq on the object itself.

var count = (from item in itemCollection
             where item.IsChecked && item.Tytle == "household"
             select item).Count();


That would make it much simpler.
 
Share this answer
 
C#
IList<GridViewRow> rows = new List<GridViewRow>();
      foreach (GridViewRow item in gvPerson.Rows)
      {
          //Enter Condition Here
          rows.Add(item);
      }
      IEnumerable<GridViewRow> irows = rows.AsEnumerable<GridViewRow>();
      Response.Write(string.Format("Numeber of Rows Using LINQ:{0}", irows.Count()));
 
Share this answer
 
Comments
mayshar 22-Oct-10 7:21am    
thanks for the reply
didnt manage to find the control for <asp:BoundField DataField="EmployeeID" HeaderText="EmployeeID"
how do I write the condition for this BoundField to be == "Household"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900