Solved

Updating datalist

Posted on 2013-06-24
4
453 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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

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…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

763 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