Solved

disable textbox in datalist

Posted on 2004-10-19
2
547 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ASP.NET e-commerce website 4 58
creating a flowchart from an algorithm 5 30
c# LinkButton OnClientClick 2 34
Name space syntax error 12 43
AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 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

15 Experts available now in Live!

Get 1:1 Help Now