Solved

disable textbox in datalist

Posted on 2004-10-19
2
544 Views
Last Modified: 2008-02-01
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.



0
Comment
Question by:csetzkorn
2 Comments
 
LVL 18

Accepted Solution

by:
tusharashah earned 125 total points
ID: 12348736
Modify your OnEdit like following:

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

     …
      switch( e.Item.ItemType )
      {
      case ListItemType.Item:
      //case ListItemType.AlternatingItem:
                      ( (DropDownList) (e.Item.FindControl( "unit" )) ).Enabled = false;
                 break;
                }

     …
}

----------------------------------------------------------------------------------------------------------------

-tushar
0
 

Author Comment

by:csetzkorn
ID: 12349227
I actually had to look for:

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

Still you comment has helped. Thanks.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

759 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now