Link to home
Start Free TrialLog in
Avatar of csetzkorn
csetzkorn

asked on

disable textbox in datalist

Dear all,

I have bound a datalist to some table in a database. Everything works fine; I can delete, edit, and update a record. I am just wondering whether it is possible to disable a textbox defined within the <EditItemTemplate> environment like this:
<EditItemTemplate>

...
   <asp:DropDownList Runat="server" ID = "unit" DataSource = '<%# getValues( "unit" ) %>' DataTextField = "unit_name" DataValueField = "unit_uid" />
...

</EditItemTemplate>

I can 'access' the value of the dropdownlist in my OnUpdate( Object source, DataListCommandEventArgs e ) method like this:

( (DropDownList) (e.Item.FindControl( "unit" )) ).SelectedItem.Value

Unfortunately, I cannot do something like this:

public void OnEdit( Object source, DataListCommandEventArgs e )
{
      variable_details_datalist.EditItemIndex = e.Item.ItemIndex;

      …

      ( (DropDownList) (e.Item.FindControl( "unit" )) ).Enabled = false;

      …
}
            

I obtain a System.NullReferenceException. I don't understand why, as all the EditItems must surely be initialised when the OnEdit handler is called?

Looking forward to your reply.

Many thanks in advance.



ASKER CERTIFIED SOLUTION
Avatar of tusharashah
tusharashah

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of csetzkorn
csetzkorn

ASKER

I actually had to look for:

if( e.Item.ItemType ==  ListItemType.EditItem )

Still you comment has helped. Thanks.