Solved

Updating datalist

Posted on 2013-06-24
4
452 Views
Last Modified: 2013-06-25
Hi,

I am updating a database from the data from datalist control. update works fine. I call call a sub procedure after the update to display grand total in label field out side the datalist. It also works but I have click the button twice. in a single click update works and displaying total inside lblTotal.Text works in a single click of the button.

 protected void btnUpdate_Click(object sender, EventArgs e)
    {

       foreach (DataListItem dli in DataList1.Items) 
            if (dli.ItemType == ListItemType.Item || dli.ItemType == ListItemType.AlternatingItem)
            {
                update.ExecuteNonQuery();

                lblTotal.Text = total.ToString();

            }
            CalculateGTotal();
        }
    }

Open in new window


Please help.

ayha
0
Comment
Question by:ayha1999
  • 2
  • 2
4 Comments
 
LVL 18

Accepted Solution

by:
Jerry Miller earned 250 total points
ID: 39271913
Is the button set to AutoPostBack="True"?

Is the label outside of the datalist in an update panel?

Either of these would probably fix it for you. I would try the AutoPostBack on the button first.
0
 
LVL 7

Author Comment

by:ayha1999
ID: 39271974
Button is outside of the datalist and user click to update.

Label is outside of the datalist and not in an update panel.
0
 
LVL 18

Expert Comment

by:Jerry Miller
ID: 39272518
Is the button set to AutoPostBack="True"?

The page is probably updating, but you are not seeing the update until the page refreshes. An update panel would allow partial page updates to see the label value change. Having the button set to AutoPostBack="True" forces the page to refresh.
0
 
LVL 7

Author Closing Comment

by:ayha1999
ID: 39274934
Thanks
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question