Solved

How do  I preselect the current database value in a populated datagrid dropdown list when in edit mode.

Posted on 2008-06-19
2
229 Views
Last Modified: 2012-05-05
First off thanks to Rafayali for his code which I am using.  
I have a editable datagrid incorporating a dropdownlist pouplated with data from the database. The function in the attached code sippet is part of the edit template which populates the dropdownlist. (thanks again Rafayali).  The problem is I cannot manage to select the current cell value in the dropdownlist so that the user sees the currently stored database value selected in the dropdownlist.  I have tried many searched solutions but so far not able to find one that works.  Can someone please help me out (VB code would be great as my C insn't great)  Thank you all.

<EditItemTemplate>

<asp:DropDownList

ID="DDLPI"

AutopostBack = "False"

Runat="server"

DataTextField = "NameInitial"

DataValueField = "ID"

Datasource='<%# BindDDL2()%>'/>

</asp:DropdownList>

</EditItemTemplate>

</asp:TemplateColumn>

Open in new window

0
Comment
Question by:dolbs
2 Comments
 
LVL 37

Accepted Solution

by:
samtran0331 earned 500 total points
Comment Utility
Your main datasource has the proper value for each row for this field correct?
So for instance, if this DDL is supposed to get the value from a field named "PI_ID" from the datagrid's datasource, try:


<EditItemTemplate>

<asp:DropDownList

ID="DDLPI"

AutopostBack = "False"

Runat="server"

DataTextField = "NameInitial"

DataValueField = "ID"

Datasource='<%# BindDDL2()%>'

SelectedValue='<%# DataBinder.Eval(Container.DataItem,"PI_ID")%>' />

</asp:DropdownList>

</EditItemTemplate>

</asp:TemplateColumn>

Open in new window

0
 

Author Closing Comment

by:dolbs
Comment Utility
Thanks.  Easy answer that I should have thought of myself.  Great service and reply.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 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

18 Experts available now in Live!

Get 1:1 Help Now