Gridview with Dropdown list

Discussion in '.NET' started by Erik1066, Sep 3, 2010.

  1. Erik1066

    Erik1066

    Joined:
    Sep 3, 2010
    Messages:
    1
    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
    Erik1066, Sep 3, 2010
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. coli@rocketmail.com

    dropdown list, gridview, and viewstate

    coli@rocketmail.com, Nov 5, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    1,889
    coli@rocketmail.com
    Nov 5, 2004
  2. =?Utf-8?B?a2Vu?=
    Replies:
    1
    Views:
    10,316
    Wiktor Zychla [C# MVP]
    Jan 23, 2006
  3. sjmyers
    Replies:
    0
    Views:
    1,745
    sjmyers
    Mar 27, 2007
  4. anonymoushamster@gmail.com
    Replies:
    2
    Views:
    430
    anonymoushamster@gmail.com
    Nov 7, 2007
  5. Paul
    Replies:
    3
    Views:
    1,007
Loading...

Share This Page