Solved

adding DropDownList to gridview selectvalue is bound to source field

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

809 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