Solved

adding DropDownList to gridview selectvalue is bound to source field

Posted on 2011-02-17
3
418 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
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 …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

729 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