Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

adding DropDownList to gridview selectvalue is bound to source field

Posted on 2011-02-17
3
Medium Priority
?
421 Views
Last Modified: 2012-05-11
I am try to add a DropDownList to a gridview where the selected value of the dropdownlist is from one of the bound fields.  

I tried the below code and that shows both fields.  I only want the dropdownlist.

<asp:BoundField DataField="sample_type_id" HeaderText="Sample Type"
                        SortExpression="sample_type_id" HeaderStyle-Font-Names="verdana, arial, helvetica;" HeaderStyle-Font-Size="9px" />
                   
                              <asp:templatefield headertext="Sample Type" HeaderStyle-Font-Names="verdana, arial, helvetica;" HeaderStyle-Font-Size="9px">
<itemtemplate>
 <asp:DropDownList ID="DropDownList4" runat="server" DataSourceID="sampleTypeInfo"
                            DataTextField="sampleTypeInfo" DataValueField="sampleType_id">
                        </asp:DropDownList>  

</itemtemplate>
</asp:templatefield>
0
Comment
Question by:kw66722
3 Comments
 
LVL 16

Expert Comment

by:Kalpesh Chhatrala
ID: 34923314
Accessing a DropDownList inside a GridView Sample Project

http://www.codeproject.com/KB/webforms/DropdownInsideGridview.aspx
0
 
LVL 1

Author Comment

by:kw66722
ID: 34923565
From that sample I am not sure how to change the selected value to the value of the bound field.

 I want the DropDownList4.selectValue = boundfield sample_type_id value

How would I get the value of the boundfield and then set the dropdownlist field.
0
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 2000 total points
ID: 34923599
remove the bound field if you don't want it in the grid view and add the selectedvalue attribute as in the code below:

<asp:DropDownList ID="DropDownList4" runat="server" DataSourceID="sampleTypeInfo"
                            DataTextField="sampleTypeInfo" DataValueField="sampleType_id" SelectedVale=<%# Bind("sample_type_id") %>
                        </asp:DropDownList>
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

773 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