Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 464
  • Last Modified:

Updating datalist

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
ayha1999
Asked:
ayha1999
  • 2
  • 2
1 Solution
 
Jerry MillerCommented:
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
 
ayha1999Author Commented:
Button is outside of the datalist and user click to update.

Label is outside of the datalist and not in an update panel.
0
 
Jerry MillerCommented:
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
 
ayha1999Author Commented:
Thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now