Not getting dropdown selected value

2 posts, 0 answers
  1. Web Services
    Web Services avatar
    243 posts
    Member since:
    Apr 2008

    Posted 15 Jun 2012 Link to this post

    I have a control within a tool tip. Whenever I click the button, I always get -1 for my selected value, not the selected value. I really don't know why I'm getting -1. Here is my code. The reviewerid at the bottom is always -1

    telerik:RadToolTip ID="PaperRevTooltip" runat="server" ManualClose="True" Modal="True"
                Position="Center" RelativeTo="BrowserWindow" ShowEvent="FromCode" Skin="Telerik"
                Title="Reviewers" Width="400" Height="400">
                <asp:Repeater ID="Repeater1" runat="server">
                        <table border="0" cellpadding="0" cellspacing="5">
                        <UC1:UControl ID="test3" runat="server" PaperID='<%# DataBinder.Eval(Container.DataItem, "PaperID")%>'
                            ReviewerID='<%# DataBinder.Eval(Container.DataItem, "ReviewerUserID")%>' reviewId='<%# DataBinder.Eval(Container.DataItem, "ReviewOfPaperID")%>' />
                <asp:SqlDataSource ID="ReviewersSqlDS" runat="server" ConnectionString="<%$ ConnectionStrings:conferencehubConnectionString %>"
                    SelectCommand="admin_PaperReviewers" SelectCommandType="StoredProcedure">
                        <asp:Parameter Name="PaperID" Type="Int16" DefaultValue="0" Direction="Input" />

    Here is the relevant code behind for that page. note the item command comes from a rad grid the tool tip shows, but with nothing but the title
    Protected Sub item_command(ByVal source As ObjectByVal As Telerik.Web.UI.GridCommandEventArgs) Handles PapersGV.ItemCommand
           Dim index As Integer
           Dim paperID As String
           If e.CommandName = "changeRev" Then
               index = e.Item.ItemIndex
               paperID = Me.PapersGV.Items(index).GetDataKeyValue("PaperID")
               Me.PaperRevTooltip.Title = Me.PapersGV.Items(index).GetDataKeyValue("PaperTitle")
               Me.PaperRevTooltip.visible = True
               Me.PaperRevTooltip.visible = False
           End If
       End Sub
    Protected Sub loadPaperReviewersData(ByVal paperID As String)
           Dim dt As DataTable
           Dim connString As String = System.Configuration.ConfigurationManager.ConnectionStrings("conferencehubConnectionString").ToString
           Dim myConnection As New Data.SqlClient.SqlConnection(connString)
           Dim strSQL As String "admin_PaperReviewers"
           Dim selectCommand As New Data.SqlClient.SqlCommand(strSQL, myConnection)
           Dim SQLReader As SqlDataReader
           Dim paperIDParam As SqlParameter
           Dim values() = {"-1""-1""0", paperID, ""}
               selectCommand.CommandType = Data.CommandType.StoredProcedure
               paperIDParam = New SqlParameter("PaperId", Data.SqlDbType.Int)
               paperIDParam.Value = paperID
               SQLReader = selectCommand.ExecuteReader()
               dt = New DataTable
               'While dt.Rows.Count < minReviewers
               If dt.Rows.Count < maxReviewers Then
               End If
               'End While
               Me.paperReviewersDT = dt
               Me.Repeater1.DataSource = dt
           Catch ex As Exception
               Response.Write("There has been an error.<br />" & ex.ToString & "<Br />" & strSQL)
           End Try
       End Sub
       Private Property paperReviewersDT() As DataTable
               Return CType(ViewState("allRevs"), DataTable)
           End Get
           Set(ByVal value As DataTable)
               ViewState("allRevs") = value
           End Set
       End Property

    Here is the control uc1
            <asp:Label ID="output" runat="server"></asp:Label>
            <asp:DropDownList ID="RevDropDownList" runat="server" DataSourceID="TrackSqlDS" DataTextField="ReviewerName"
            <asp:CustomValidator ID="revValidator" runat="server" ErrorMessage="*"></asp:CustomValidator>
            <asp:Button ID="AddButton" runat="server" Text="Add" CommandName="AddReviewer" />
            <asp:Button ID="DelButton" runat="server" Text="Delete" CommandName="DeleteReviewer"
                Visible="false" />
            <asp:Button ID="UpdateButton" runat="server" Text="Update" CommandName="UpdateReviewer"
        <asp:SqlDataSource ID="TrackSqlDS" runat="server" ConnectionString="<%$ ConnectionStrings:conferencehubConnectionString %>"
            SelectCommand="admin_AllReviewers" SelectCommandType="StoredProcedure" OnSelecting="TrackItDataSource_Selecting">
                <asp:Parameter Name="PaperID" Type="Int32" />

    And the control code
        Private _ReviewerID As Integer
        Private _ReviewID As Integer
        Public Property reviewId() As Integer
                Return CType(ViewState("reviewId"), Integer)
            End Get
            Set(ByVal value As Integer)
                ViewState("reviewId") = value
            End Set
        End Property
        Public Property PaperID() As Integer
                Return CType(ViewState("paperId"), Integer)
            End Get
            Set(ByVal value As Integer)
                ViewState("paperId") = value
            End Set
        End Property
        Public Property ReviewerID() As Integer
                Return Me.RevDropDownList.SelectedItem.Value
            End Get
            Set(ByVal value As Integer)
                _ReviewerID = value
            End Set
        End Property
        Public ReadOnly Property ReviewerName() As String
                Return Me.RevDropDownList.SelectedItem.Text
            End Get
        End Property
    #Region "SQLDS Events"
        Protected Sub TrackItDataSource_Selecting(ByVal sender As ObjectByVal As SqlDataSourceSelectingEventArgs)
            e.Command.Parameters.Item(0).Value = PaperID
        End Sub
    #End Region
        Protected Sub rev_Bound(ByVal sender As ObjectByVal As System.EventArgs) Handles RevDropDownList.DataBound
            Dim defaultItem As New ListItem("- Select Reviewer -""-1")
            RevDropDownList.Items.Insert(0, defaultItem)
            output.Text = "test"
            If _ReviewerID <> 0 Then
                RevDropDownList.Items.FindByValue(_ReviewerID).Selected = True
            End If
            If isValid() Then
                AddButton.Visible = False
                UpdateButton.Visible = True
                DelButton.Visible = True
            End If
        End Sub
        Public Function isValid() As Boolean
            If RevDropDownList.SelectedIndex = 0 Then
                revValidator.IsValid = False
                Return False
                Return True
            End If
        End Function
        Protected Sub Page_Load(ByVal sender As ObjectByVal As System.EventArgs) Handles Me.Load
            output.Text = "test"
        End Sub
        Protected Sub AddButton_Click(ByVal sender As ObjectByVal As System.EventArgs) Handles AddButton.Click
            If isValid() Then
                ReviewerID = Me.RevDropDownList.SelectedItem.Value
            End If
        End Sub

  2. Marin Bratanov
    Marin Bratanov avatar
    5138 posts

    Posted 18 Jun 2012 Link to this post


    I would advise that you debug your code and follow the data from your datasources, the items that are selected in the dropdowns and see when the change occurs. What it seems to me after examining your code is that in the button click event you bind the dropdown list again, and you insert another default item:
    Dim defaultItem As New ListItem("- Select Reviewer -", "-1")
    RevDropDownList.Items.Insert(0, defaultItem)

    as the button click's event handelr is the last method to be called in the page lifecycle. This means that the initial item that is selected will be lost. You can consider binding the dropdown list only the first time the user control is loaded and not on each postback.

    If you replace the tooltip with a standard ASP panel that you show and hide in the grid's event you would have the same issues, so I advise that you resolve them in the simplest scenario you have, because they are not related to the RadToolTip.

    All the best,
    Marin Bratanov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top