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. EditItemIn dex = e.Item.ItemIndex;
…
( (DropDownList) (e.Item.FindControl( "unit" )) ).Enabled = false;
…
}
I obtain a System.NullReferenceExcept ion. 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.
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.
…
( (DropDownList) (e.Item.FindControl( "unit" )) ).Enabled = false;
…
}
I obtain a System.NullReferenceExcept
Looking forward to your reply.
Many thanks in advance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
if( e.Item.ItemType == ListItemType.EditItem )
Still you comment has helped. Thanks.