Gridview with Dropdown list

Sep 3, 2010
Reaction score
I have a gridview that contains a dropdownlist in a templatefield, what I want to do is gey the selected value from the drop down list when the row is selected, I have tried using .FindControl and all I get is the first line in the dropdown list, is it possible to do it ot do I need to loop through all the rows?

Code for aspx page

<asp:GridView ID="GvCourseList" runat="server" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None"
BorderWidth="1px" CellPadding="3" AutoGenerateColumns="False" OnRowCommand="GvCourseList_RowCommand">
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
<asp:BoundField DataField="CouCmaid" HeaderText="Mast.Id" SortExpression="CouId" >
<ItemStyle Wrap="False" />
<asp:BoundField DataField="CouId" HeaderText="Inst.Id" SortExpression="CouId" >
<ItemStyle Wrap="False" />
<asp:BoundField DataField="CenName" HeaderText="Centre" />
<asp:BoundField DataField="Aol_Desc" HeaderText="SSA" SortExpression="Ssa" />
<asp:BoundField DataField="SubName" HeaderText="Title" SortExpression="CouLocalDesc" />
<asp:BoundField DataField="StartDate" HeaderText="Start Date" SortExpression="StartDate" />
<asp:BoundField DataField="CshedDay_concat" HeaderText="Day(s)" />
<asp:BoundField DataField="CouStateDesc" HeaderText="State" />
<asp:TemplateField HeaderText="Description">
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("CouLocalDesc") %>'></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server" TextMode="MultiLine" ReadOnly="true" Width="300px"
Text='<%# Bind("CouLocalDesc") %>'></asp:TextBox>
<ItemStyle Font-Size="X-Small" />
<asp:TemplateField HeaderText="Go Next">
<asp:DropDownList ID="DdlGoItem" runat="server" AutoPostBack="false" OnSelectedIndexChanged="DdlGoItemIndexChanged">
<asp:ListItem Value="Select">Select</asp:ListItem>
<asp:ListItem Value="Details">Details</asp:ListItem>
<asp:ListItem Value="Sessions">Sessions</asp:ListItem>
<asp:ListItem Value="Enrol">Enrol</asp:ListItem>
<asp:ListItem Value="Reports">Reports</asp:ListItem>
<asp:ListItem Value="Exams">Exam Results</asp:ListItem>
<asp:ButtonField ButtonType="Button" CommandName="Go" Text="Go" />
<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
<AlternatingRowStyle BackColor="#F7F7F7" />

Code for aspx.vb page
Sub GvCourseList_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)

If e.CommandName = "Go" Then
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim row As GridViewRow = GvCourseList.Rows(index)

Session("CourseId") = Server.HtmlDecode(row.Cells(1).Text)

'Dim DdlNextPage As New DropDownList
'DdlNextPage = (GvCourseList.Rows(index).FindControl("DdlGoItem"))

Dim DdlNextPage = CType(row.FindControl("DdlGoItem"), DropDownList)
DdlNextPage.SelectedValue = (DdlNextPage.SelectedValue).ToString()

Dim sNextPage As String
'sNextPage = GvCourseList.Rows(index).Cells(9).Text.ToString
'DdlNextPage =

sNextPage = DdlNextPage.SelectedValue
Select Case sNextPage
Case "Details"
Case "Enrol"
Case "Reports"
Case "Sessions"
Case "Exams"
Case Else
'LblError.Text = LblError.Text & "An Error has Occoured while selecting next page"
End Select
LblError.Text = LblError.Text & "An Error has Occoured while selecting a row"
End If
LblError.Visible = True
End Sub


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question