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
246 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
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

777 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