I posted this before and thought my problem was solved but it wasn't. Can anyone out ther tell me how to get the value of a DropDownList within a GridView. I can't use the e.CommandArgument like I thought because I'm already passing information through it. My code for my template field is as follows:
<ItemTemplate>
<table>
<tr>
<td align="center">
<asp:DropDownList ID="cboRank" runat="server" AutoPostBack="False"
DataSourceID="SqlDataSourceRank" DataTextField="rank" DataValueField="rank">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSourceRank" runat="server"
ConnectionString="<%$ ConnectionStrings:MySchoolBizDB %>"
SelectCommand="SELECT DISTINCT [rank] FROM [collegefavs]
WHERE ([memberid] = @memberid) ORDER BY [rank]">
<SelectParameters>
<asp:ControlParameter ControlID="lblMemberID" Name="memberid" PropertyName="Text" />
</SelectParameters>
</asp:SqlDataSource>
</td>
</tr>
<tr>
<td>
<asp:Button ID="Update" runat="server" CommandName="UpdateClick" Text="Update Rank" CommandArgument='<%# Eval("collegeid") %>'/>
</td>
</tr>
</table>
</ItemTemplate>
I need to find the value for my update statement which is as follows:
If e.CommandName = "UpdateClick" Then
Dim sqlGetInfo As New SqlCommand("SELECT * FROM collegefavs " & _
"WHERE memberid = '" & lblMemberID.Text & "' " & _
"AND collegeid = '" & e.CommandArgument.ToString & "'", _
dbConnection)
Dim rdrGetInfo As SqlDataReader, newRank As Integer = 0
Try
dbConnection.Open()
rdrGetInfo = sqlGetInfo.ExecuteReader
Do While rdrGetInfo.Read
dbDataSource.UpdateCommandType = SqlDataSourceCommandType.Text
dbDataSource.UpdateCommand = "UPDATE collegefavs SET rank = @ rank " & _
"WHERE memberid = '" & lblMemberID.Text & "' " & _
"AND collegeid = '" & e.CommandArgument.ToString & "'"
'dbDataSource.UpdateParameters.Add("rank", GridView2.FindControl("cboRank").
Loop
What is the correct syntax for the above line dbDataSource.UpdateParameter.Add("rank", ????)
Someone please help me. I'm fairly new to this and I've been working on this for 3 or 4 days now with no success.