Solved

adding DropDownList to gridview selectvalue is bound to source field

Posted on 2011-02-17
3
414 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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

919 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

22 Experts available now in Live!

Get 1:1 Help Now