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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

840 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