Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
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
Medium Priority
?
275 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
[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 37

Accepted Solution

by:
samtran0331 earned 2000 total points
ID: 21822251
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
ID: 31468749
Thanks.  Easy answer that I should have thought of myself.  Great service and reply.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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 this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

662 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