Jump to content
Fórum Script Brasil
  • 0

Soma ItemDataBound


henriquesmarjassi
 Share

Question

Bom dia Pessoal,

Preciso fazer algo que na teoria era pra ser simples, mas não está dando certo, preciso somar as linhas de um campo no datagridview e mostrar no rodapé, o que achei na internet me dá a opção de fazer isso via VB e com aspx.

Só que meu projeto tem o arquivo ascx.cs.e nesse tipo de arquivo não sei o q fazer, só pra terem uma idéia, segue abaixo o exemplo que achei na internet de fazer no aspx

On the code behind file (.aspx.cs), we define the ‘itemDataBound’ method for handling the ItemDataBound Event.

&nbsp&nbsp&nbsp float total = 0; protected void itemDataBound(object sender, DataGridItemEventArgs
e) { if (e.Item.ItemType!=ListItemType.Header && e.Item.ItemType!=ListItemType.Footer) {
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp &nbs p; total += float.Parse(e.Item.Cells[1].Text);
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp e.Item.ForeColor = System.Drawing.Color.Blue;
&nbsp&nbsp&nbsp&nbsp&nbsp }
&nbsp&nbsp&nbsp&nbsp&nbsp else if (e.Item.ItemType == ListItemType.Footer)
&nbsp&nbsp&nbsp&nbsp&nbsp {
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp e.Item.Cells[0].Text = "Total";
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp e.Item.Cells[1].Text = total.ToString();
&nbsp&nbsp&nbsp&nbsp&nbsp }
&nbsp&nbsp&nbsp&nbsp }

The new datagrid looks like this when rendered on the page:

071904figure2.gif

Só lembrando meu projeto está em ascx.cs, alguém tem alguma idéia de como fazer isso?

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



  • Forum Statistics

    • Total Topics
      150.1k
    • Total Posts
      647k
×
×
  • Create New...