Solved

adding DropDownList to gridview selectvalue is bound to source field

Posted on 2011-02-17
3
413 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
Comment Utility
Accessing a DropDownList inside a GridView Sample Project

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

Author Comment

by:kw66722
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
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…

762 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

9 Experts available now in Live!

Get 1:1 Help Now