Click here to Skip to main content
15,887,338 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
int productsum = 0;
    public string CalTotal(int total)
    {
           productsum += total;
           return total.ToString();
    }
    public string GetSum()
    {
        return productsum.ToString();
    }



Aspx code for GridView1 with checkbox. I want to get only checked cells and pass it to another page

XML
<asp:GridView ID="GridView1" ShowFooter="true" OnRowDataBound="GridView1_RowDataBound" runat="server" AutoGenerateColumns="False" DataKeyNames="korisnikID" DataSourceID="SqlDataSource1" Height="320px" Width="763px" CellPadding="4" Font-Names="Calibri" ForeColor="#333333" HorizontalAlign="Center" font-size="Medium" GridLines="None" CssClass="auto-style9" >

      
        <Columns>
            <asp:BoundField DataField="fakturaID" HeaderText="Број на сметка" InsertVisible="true" ReadOnly="True" SortExpression="fakturaID" HeaderStyle-Width="100px"/>

            <asp:BoundField DataField="korisnikID" HeaderText="korisnikID" SortExpression="korisnikID" Visible="False" />
            <asp:BoundField DataField="ЗаПериод" HeaderText="За период" SortExpression="ЗаПериод" DataFormatString="{0:dd-MMM-yyyy}" HeaderStyle-Width="100px"/>


          <asp:TemplateField HeaderText="Износ" HeaderStyle-Width="100px">
              <ItemTemplate>
<asp:Label ID="lbliznos" runat="server" Text='<%# Eval("Износ")%>'/>
              </ItemTemplate>
          </asp:TemplateField>

            <asp:BoundField DataField="ДатумНаПлаќање" HeaderText="Датум на плаќање" SortExpression="ДатумНаПлаќање"  DataFormatString="{0:dd-MMM-yyyy}" HeaderStyle-Width="100px" />
                 <asp:TemplateField HeaderText="Побарува" HeaderStyle-Width="100px">
<ItemTemplate>
<asp:Label ID="lblpobaruva" runat="server" Text='<%# Eval("Побарува")%>'/>
</ItemTemplate>



                 <FooterTemplate>
                <asp:Label ID="Label2" runat="server" Text="Вкупно сума за плаќање"></asp:Label>
            </FooterTemplate>

                 </asp:TemplateField>

        <asp:TemplateField HeaderText="Должи" HeaderStyle-Width="100px">
<ItemTemplate>
<asp:Label ID="lblListPrice" runat="server" Text='<%#CalTotal(int.Parse(Eval("Должи").ToString()))%>'/>
</ItemTemplate>

            <FooterTemplate>
                <asp:Label ID="lblTotal" runat="server" Text='<%# GetSum() %>'/>
            </FooterTemplate>
        </asp:TemplateField>
             <asp:TemplateField HeaderText="Означи за плаќање">
                <ItemTemplate>
                    <asp:CheckBox ID="CheckBox1"  runat="server"  onclick="javascript: DisableButton()"/>

                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
Posted
Comments
Laiju k 28-Apr-14 5:08am    
are you asking .cs code or javascript code
R.Elena 28-Apr-14 5:10am    
.cs code

1 solution

C#
int count = gvPurchaseEntry.Rows.Count;
for (i = 0; i < count; i++)
   {
   CheckBox chk= (CheckBox )gvPurchaseEntry.Rows[i].FindControl("CheckBox1");
   if(chk.Checked==true)
   {
      your code
   }
}
 
Share this answer
 
v2
Comments
R.Elena 28-Apr-14 5:27am    
Error message : CallTotal(int) : not all code paths return a value
Laiju k 29-Apr-14 2:45am    
int productsum = 0; intialise the productsum before the for loop
and use this inside loop productsum += total;

then productsum will be your output
R.Elena 29-Apr-14 6:59am    
Ok thanks !

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