Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Gridview with Dropdown list

Reply
Thread Tools

Gridview with Dropdown list

 
 
Erik1066 Erik1066 is offline
Junior Member
Join Date: Sep 2010
Posts: 1
 
      09-03-2010
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>
<aspropDownList 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>
</aspropDownList>
</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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
gridview control, trying to set selected value in a dropdown list Paul ASP .Net 3 06-26-2008 10:55 PM
1 Gridview. Dropdown A is column from database, Dropdown B is column from database, Data in A and B must be from same row. anonymoushamster@gmail.com ASP .Net 2 11-07-2007 12:40 PM
displaying dropdown list values in edititemtemplate in gridview sjmyers ASP .Net 0 03-27-2007 09:08 AM
GridView edit validation, edit dropdown list, delete popup confirm =?Utf-8?B?a2Vu?= ASP .Net 1 01-23-2006 12:51 PM
dropdown list, gridview, and viewstate coli@rocketmail.com ASP .Net 0 11-05-2004 01:33 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57