Gridview with Dropdown list

Joined
Sep 3, 2010
Messages
1
Reaction score
0
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" />
<Columns>
<asp:BoundField DataField="CouCmaid" HeaderText="Mast.Id" SortExpression="CouId" >
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="CouId" HeaderText="Inst.Id" SortExpression="CouId" >
<ItemStyle Wrap="False" />
</asp:BoundField>
<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">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("CouLocalDesc") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" TextMode="MultiLine" ReadOnly="true" Width="300px"
Text='<%# Bind("CouLocalDesc") %>'></asp:TextBox>
</ItemTemplate>
<ItemStyle Font-Size="X-Small" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Go Next">
<ItemTemplate>
<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:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField ButtonType="Button" CommandName="Go" Text="Go" />
</Columns>
<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" />
</asp:GridView>


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"
Server.Transfer("~/CourseDetail.aspx")
Case "Enrol"
Server.Transfer("~/CourseEnrol.aspx")
Case "Reports"
Server.Transfer("~/CourseReports.aspx")
Case "Sessions"
Server.Transfer("~/CourseSession.aspx")
Case "Exams"
Server.Transfer("~/CourseExams.aspx")
Case Else
'LblError.Text = LblError.Text & "An Error has Occoured while selecting next page"
End Select
Else
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

Similar Threads


Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top