Solved

I want dropdownlist to appear in gridview ONLY when in edit mode

Posted on 2008-10-29
2
295 Views
Last Modified: 2013-11-26
I have a working, editable gridview. One of the columns in my gridview is employeeID, which is represented by a dropdownlist control (DataTextField="employeeName", DataValueField="employeeID"). Another column is an "edit" link.

So when I load the page, I see my gridview with all 10 records. Each of the 10 records has its own "edit" link. Each of the 10 records also has its own "employeeID" dropdownlist column.

When I click "edit" for one of the records and make a change in its "employeeID" dropdown menu, then click "update", my changes show up fine in my gridview. So the general plumbing works.

My question is this: Is it possible to show the dropdownlist control ONLY for the active record (i.e. when the user has clicked "edit" for a particular record), instead of showing the dropdownlist control for ALL records when just in view mode (vs. edit mode). It just seems pointless to have all those dropdownmenus populated when I could just display the employee name (for all but the selected/active record) as a label when in view mode.

I'm particularly interested in whether there is a "no-code-necessary" way of doing this in Visual Studio 2005.

Thanks!
0
Comment
Question by:reallyv
2 Comments
 
LVL 7

Accepted Solution

by:
imateyelectronics earned 250 total points
ID: 22837785
If I am understanding you correctly you want to be able to show the drop down list only when editing a single item within the gridview edit mode.  For this purpose you didn't really need an Editable gridview at all.  You could have simple just edited the item templates of your columns, while dragging the drop down list within the edit template view.

For simplicity state I'll show you an example with a gridview named gridview1 and a single column named Testfield.  The testfield column is a gridview templatefield.  I simply dragged a label within the item template and a dropdownlist within the edit template.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">

            <Columns>

                <asp:TemplateField HeaderText="TestField">

                    <EditItemTemplate>

                        <asp:DropDownList ID="DropDownList1" runat="server">

                        </asp:DropDownList>

                    </EditItemTemplate>

                    <ItemTemplate>

                        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

                    </ItemTemplate>

                </asp:TemplateField>

            </Columns>

        </asp:GridView>

Open in new window

0
 

Author Comment

by:reallyv
ID: 22845650
What a revelation! 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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

747 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

12 Experts available now in Live!

Get 1:1 Help Now