[Webinar] Streamline your web hosting managementRegister Today


Getting the selected value of a dropdown in the edititemtemplate of a gridview that is tied to a datasource

Posted on 2008-02-06
Medium Priority
Last Modified: 2008-02-07
Ok basically I've tried the solutions that I've seen on here and none of them have worked for me.  I have a dropdown list in a gridview in an edititemtemplate.  I need for the selected value to display in the series dropdownbox when the edit link is clicked.  I tried selectedvalue but only got the selectedvalue not in the list error.  Please advise.  Here is my code
<%-- PROGRAM --%>
        <asp:templatefield HeaderText="Program" ItemStyle-Width="60%">
            <ItemTemplate><asp:label id="lblProgramTitle" runat="server" text='<%# Bind("ProgramTitle") %>' /></ItemTemplate>
                        <td><asp:DropDownList ID="ddlSeries" runat="server" DataTextField="SeriesName" DataValueField="SeriesID" OnSelectedIndexChanged="GetPrograms" AutoPostBack="true" /></td>
                        <td><asp:DropDownList ID="ddlPrograms" DataTextField="ProgramTitle" DataValueField="ProgramID" runat="server" /></td>
Code Behind:
Protected Sub grdPlaylist_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdPlaylist.RowDataBound
            Dim objData As New AmazingFacts.Modules.MediaManager.MediaManagerController
            Dim recDataList As List(Of AmazingFacts.Modules.MediaManager.MediaManagerInfo)
            Dim ddlSeries As DropDownList
            If e.Row.RowType = DataControlRowType.DataRow Or e.Row.RowType = DataControlRowType.Footer Or e.Row.RowType = DataControlRowType.EmptyDataRow Then
                ddlSeries = CType(e.Row.FindControl("ddlSeries"), DropDownList)
                If Not (ddlSeries) Is Nothing Then
                    recDataList = objData.GetSeriesProfiles(ModuleId)
                    ddlSeries.DataSource = recDataList
                    ddlSeries.Items.Insert(0, New ListItem("--- Please select one ---", ""))
                End If
            End If
        End Sub
Protected Sub grdPlaylist_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles grdPlaylist.RowEditing
            grdPlaylist.EditIndex = e.NewEditIndex
        End Sub
Would the code to accomplish that I'm trying to do go in the rowdatabound method or rowediting?

Open in new window

Question by:afacts
  • 3

Author Comment

ID: 20842357

I had a similar problem with a page of mine.   The code that says:

ddlSeries = CType(e.Row.FindControl("ddlSeries"), DropDownList)

Needs to be modified slightly.  

ddlSeries = CType(CType(gv, GridView).Rows(i).FindControl("ddlSeries"), DropDownList)

In this code gv is the gridview that the dropdownlist appears in.  That worked for me.  Hope that helps.

Author Comment

ID: 20842623
Well this code

ddlSeries = CType(e.Row.FindControl("ddlSeries"), DropDownList)

is actually working fine.  I'm not having problems with that.  I was wondering what code to add and where to get the selected value for the dropdown when its in editmode ... should the code be in the rowdatabound or rowediting method?  I've tried both but have not been successful.  

Accepted Solution

afacts earned 0 total points
ID: 20842987

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

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

Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
Magento is the best technology for eCommerce start-ups as it offers the technical expertise and visual appeal to create a store that pulls sales and earns high ROI (Return on investment).
The viewer will learn how to count occurrences of each item in an array.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
Suggested Courses
Course of the Month9 days, 18 hours left to enroll

591 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