473,402 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

GridView Edit DropDownList Selected - .Net 2.0

I have a gridview in .net 2.0 with a dropdownlist of two items - that being "active" and "inactive".

<EditItemTemplate> <asp:DropDownList ID="ddlStatus" runat="server" AutoPostBack="true">
<asp:ListItem Text="active" Value="active"></asp:ListItem>
<asp:ListItem Text="inactive" Value="inactive"></asp:ListItem
</asp:DropDownList>
</EditItemTemplate>

I also have AutoGenerateEditButton="true" AutoGenerateDeleteButton="true".
So when I run the application and click the edit button on a row I get the values for the other fields in textboxes as I expect, but for the dropdownlist, I get the two values in a dropdown, but the one that was chosen for that row already is NOT showing as the first one (selected).

With asp.net 1.1 I used the ItemDataBound event to handle getting the selected value for each dropdownlist when being displayed in edit. The ItemDataBound event is no longer available for this "new" datagrid know as the gridview.

How can I capture the current value of a row's dropdownlist as the selected one in that list and in what event can this be done?
May 22 '07 #1
1 13562
I have a gridview in .net 2.0 with a dropdownlist of two items - that being "active" and "inactive".

<EditItemTemplate> <asp:DropDownList ID="ddlStatus" runat="server" AutoPostBack="true">
<asp:ListItem Text="active" Value="active"></asp:ListItem>
<asp:ListItem Text="inactive" Value="inactive"></asp:ListItem
</asp:DropDownList>
</EditItemTemplate>

I also have AutoGenerateEditButton="true" AutoGenerateDeleteButton="true".
So when I run the application and click the edit button on a row I get the values for the other fields in textboxes as I expect, but for the dropdownlist, I get the two values in a dropdown, but the one that was chosen for that row already is NOT showing as the first one (selected).

With asp.net 1.1 I used the ItemDataBound event to handle getting the selected value for each dropdownlist when being displayed in edit. The ItemDataBound event is no longer available for this "new" datagrid know as the gridview.

How can I capture the current value of a row's dropdownlist as the selected one in that list and in what event can this be done?
Solution:
The RowDataBound handler was not executing, so I added:
OnRowDataBound="gv2_RowDataBound" to the gridview control.
I could address the dropdownlist (edititemtemplate) when in the RowDataBound event handler, I had a RowState of Edit...

if (e.Row.RowState == DataControlRowState.Edit)
{
DropDownList ddStatus = (DropDownList)e.Row.FindControl("ddlStatus");
ddStatus.SelectedValue = stat;
}
May 22 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Chris Kettenbach | last post by:
Good morning all, I am sure this has been asked but I did not see anything. I have a datalist control. In the edititemtemplate I have a dropdownlist. I know on the itemdatabound event is where I...
1
by: ken | last post by:
I added a CustomValidator in Gridview edit mode, how to set the cusomvalidator to invalid or valid when check the update
1
by: rockdale | last post by:
Hi, all Is there a way to dynamically attach a regularexpressionvalidator to a textbox base on dropdownlist selected item? Let's say I have a dropdownlist list all contact type - phone, cell,...
1
by: SubashiniKumaar | last post by:
how to copy dropdownlist selected items to another dropdownlist in Asp.net using C# codings
2
by: =?Utf-8?B?cm9kY2hhcg==?= | last post by:
hey all, i'm in a gridview edit row that has a DropDownList in one column and a status Label in the 2nd column. When i changed the value in the dropdownlist, there's a client-side javascirpt...
1
by: Lakshmi GagniShetty | last post by:
In gridview edit event it is possible to display dropdownlist instead of text boxes.I am using dotnet 2005. Here the gridview autogenerate columns are false. And I had only one row and columns...
1
by: arunbojan | last post by:
Hi All, I have an editable datagrid with 10 columns, one of those is ddl column which I used for showing the status.... By default all the columns are readonly, when user clicks edit,...
1
by: anithaapr05 | last post by:
Dear All How to edit DropDownList in asp.net Thanks Anitha
3
by: Shashirk | last post by:
I have a Maniform with a sub form attached to it, when ever people enter the data and save, all the records in the sub form with turn to "Allowedits = False" – This is the code that has been given on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.