Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Gridview with rows calcul

Gridview with rows calcul

Scheduled Pinned Locked Moved ASP.NET
help
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    amina89
    wrote on last edited by
    #1

    Hello I have a gridview with this form ID_student -------exam_mark1 ------exam_mark2-----average to calculate the average score I used this code double average = 0; foreach (GridViewRow MRow in GridView1.Rows) { average = double.Parse(MRow.Cells[2].Text ) + double.Parse(MRow.Cells[3].Text); average = average / 2; MRow.Cells[4].Text = moyenne.ToString(); } but it returns me the following error: The format of the input string is incorrect. Help me ,thanks

    N B 2 Replies Last reply
    0
    • A amina89

      Hello I have a gridview with this form ID_student -------exam_mark1 ------exam_mark2-----average to calculate the average score I used this code double average = 0; foreach (GridViewRow MRow in GridView1.Rows) { average = double.Parse(MRow.Cells[2].Text ) + double.Parse(MRow.Cells[3].Text); average = average / 2; MRow.Cells[4].Text = moyenne.ToString(); } but it returns me the following error: The format of the input string is incorrect. Help me ,thanks

      N Offline
      N Offline
      NeverHeardOfMe
      wrote on last edited by
      #2

      the Cells collection is zero-based, so you want to average Cells(1) and Cells(2) adn put the answer in Cells(3), not 2, 3 adn 4 as you have it. But what a horrible way of doing things...on teh sassumption that these results are pulled from a database, why not pull the average directly out of that in your select statement? Or at least calculate the average in teh RowDataBound event....

      1 Reply Last reply
      0
      • A amina89

        Hello I have a gridview with this form ID_student -------exam_mark1 ------exam_mark2-----average to calculate the average score I used this code double average = 0; foreach (GridViewRow MRow in GridView1.Rows) { average = double.Parse(MRow.Cells[2].Text ) + double.Parse(MRow.Cells[3].Text); average = average / 2; MRow.Cells[4].Text = moyenne.ToString(); } but it returns me the following error: The format of the input string is incorrect. Help me ,thanks

        B Offline
        B Offline
        Brij
        wrote on last edited by
        #3

        amina89 wrote:

        but it returns me the following error: The format of the input string is incorrect.

        Did you try to debug your code? Debugging if for this purpose only. As already suggested, better to do this calcaluation and assiging in rowdatabound event.

        Cheers!! Brij My Blog:http://brijbhushan.wordpress.com
        Check my latest Article :ViewState - Various ways to reduce performance overhead

        A 1 Reply Last reply
        0
        • B Brij

          amina89 wrote:

          but it returns me the following error: The format of the input string is incorrect.

          Did you try to debug your code? Debugging if for this purpose only. As already suggested, better to do this calcaluation and assiging in rowdatabound event.

          Cheers!! Brij My Blog:http://brijbhushan.wordpress.com
          Check my latest Article :ViewState - Various ways to reduce performance overhead

          A Offline
          A Offline
          amina89
          wrote on last edited by
          #4

          Thanks all ; I still have the same error. I forgot to say that the gridview is in edit mode for columns -exam_mark1 ,-exam_mark2 and I do not know if this is the cause. <asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False" BackColor="White" BorderColor="#CCCCCC" BorderWidth="1px" CellPadding="4" CssClass="th" DataKeyNames="NUM_INSCRIPTION" Width ="60%" Height="9%" PagerStyle-CssClass="note" Style="position: absolute; left: 126px; top: 159px;" > <FooterStyle BackColor="White" ForeColor="#000066" /> <RowStyle ForeColor="#000066" /> <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="White" CssClass="note" ForeColor="#000066" HorizontalAlign="Left" /> <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" /> <Columns> <asp:TemplateField HeaderText="IDStudent"> <ItemStyle CssClass="td00" /> <ItemTemplate> <asp:Label ID="lblUserID1" runat="server" Text='<%# Eval("NUM_INSCRIPTION") %>'></asp:Label> <itemstyle cssclass="td00" /> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="StudentName"> <ItemStyle CssClass="td01" /> <ItemTemplate> <asp:Label ID="lblUserID2" runat="server" Text='<%# Eval("NOM_PRENOM_ETUDIANT_ARABE") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="mark1"> <ItemTemplate> <asp:Label ID="lblLastName1" runat="server" Text='<%# Eval("111") %>' Visible='<%# !(bool) IsInEditMode %>'></asp:Label> <asp:TextBox ID="moyt1" runat="server" Text='<%# Eval("111") %>' Visible='<%# IsInEditMode %>'></asp:TextBox> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="mark2"> <ItemStyle CssClass="td02" /> <ItemTemplate>

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups