This is a common error

Source: Internet
Author: User
Solution:
You put it in OnItemDataBound for processing and can achieve your goal only when you determine that ItemType is EDIT.
Cause:
In the Edit event, the controls in EditItemTemplate have not been created yet.
The precondition is that the data must be bound and created only after the OnEditCommand event is passed. This is why the Update event can be operated as usual.
Similar code like this
Private void maid (object sender, System. Web. UI. WebControls. DataGridItemEventArgs e)
        {
ListItemType itemtype = e. Item. ItemType;
If (itemtype = ListItemType. EditItem)
       {
CheckBoxList chk = (CheckBoxList) e. Item. FindControl ("chkClientType ");
This can meet your requirements. This should also be a standard and perfect solution.
My friend Fei Dao has some other solutions to this problem. I will refer to his article below and I will also give you a reference.
(2) FindControl method problems
Problem:
We all know that there is a FindControl method in all the control sets. The most commonly used method is the operation of the DataGrid on the controls in items. This is a very useful method that allows us to quickly find the control we want, but it is also the most unstable method I have ever encountered.
This method is usually used in items, but the control is often not found in the DataGrid and DataList events !! The DataGrid is a little better. The events in DataList are terrible. The control cannot be found in 100% !! This control exists in a living environment and can be found in the Controls collection. I have already discovered this problem in Beta2. I thought Microsoft would correct it in the official version. I don't know if no one raised it? Still not found, the official version is still like this.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.