Solved

disable textbox in datalist

Posted on 2004-10-19
2
557 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

736 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