Solved

Updating datalist

Posted on 2013-06-24
4
448 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now