Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

disable textbox in datalist

Posted on 2004-10-19
2
Medium Priority
?
569 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 250 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

618 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