[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How do I get selectevalue from DDL into ODS insert?

Posted on 2010-09-15
6
Medium Priority
?
402 Views
Last Modified: 2012-05-10
I have a form with an objectdatasource in it and three simple controls. I want to insert the selectedvalue from a databound dropdownlist into the objectdatasouce insert parameter "CommitteeID". I've tried several different ways and it's just not working. This is the latest iteration:

EVerything else works, but the selected value of the dropdownlist. It's almost like the insert happens in the page cycle prior to the dropdownlist selectedvalue coming back from viewstate. Please help. This is driving me crazy. This should be VERY simple.
<table style="width: 100%">
        <tr>
            <th>
                Committee:
            </th>
            <td>
                <asp:DropDownList ID="ddlCommittee" runat="server" DataSourceID="odsCommittees" DataTextField="CommitteeName"
                    DataValueField="CommitteeID" EnableViewState="true">
                </asp:DropDownList>
            </td>
        </tr>
        <tr>
            <th>
                Question:
            </th>
            <td>
                <asp:TextBox ID="txtQuestion" runat="server" Height="250px" TextMode="MultiLine"
                    Width="100%"></asp:TextBox>
                <br />
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Please enter your question above."
                    ControlToValidate="txtQuestion" Display="Dynamic"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <th>
                Public?
            </th>
            <td>
                <asp:CheckBox ID="cbPublic" runat="server" />
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <asp:Button ID="Button1" runat="server" Text="Send" CommandName="Insert" />
            </td>
        </tr>
    </table>
    <asp:ObjectDataSource ID="odsCommittees" runat="server" FilterExpression="IsActiveCommittee=1"
        OldValuesParameterFormatString="{0}" SelectMethod="GetData" TypeName="SapaDAL.CommitteesTableAdapters.CommitteesTableAdapter">
    </asp:ObjectDataSource>
    <asp:ObjectDataSource ID="odsQuestion" runat="server" 
        InsertMethod="AskQuestion" OldValuesParameterFormatString="original_{0}" 
        SelectMethod="GetQuestionByRowGuid" TypeName="SapaDAL.QandADAL+QandA">
        <SelectParameters>
            <asp:Parameter DbType="Guid" Name="RowGuid" />
        </SelectParameters>
        <InsertParameters>
            <asp:Parameter DbType="Guid" Name="RowGuid" />
            <asp:ControlParameter ControlID="txtQuestion" Name="Question" 
                PropertyName="Text" Type="String" />
            <asp:ControlParameter ControlID="ddlCommittee" Name="CommitteeID" 
                PropertyName="SelectedValue" Type="Int32" />
            <asp:Parameter Name="Questioner" Type="Int32" />
            <asp:ControlParameter ControlID="cbPublic" Name="AllowPublic" 
                PropertyName="Checked" Type="Boolean" />
        </InsertParameters>
    </asp:ObjectDataSource>




 Private _newRowID As Guid
    Private _notificationSubject As String = "SAPA Question Submission"
    Private _notificationMsg1 As String = "Your question was successfully submitted to SAPA at " & Date.UtcNow & " UTC. You will be notified via email and the SAPA website when an answer has been submitted. Thank you for you participation."

    Private Sub Notify()
        If _newRowID <> Guid.Empty Then
            ' send to user
            Dim sbp As New SapaBasePage
            sbp.SendNotificationToCurrentUser(_notificationSubject, _notificationMsg1)
            ' send to sapa
            Dim _nh As New NotificationHelper.QandA
            _nh.SendQuestionAdminEmail(_newRowID)
        End If
    End Sub

    Protected Sub ddlCommittee_DataBound(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim cb As ASPxComboBox = CType(sender, ASPxComboBox)
        ' cb.Items.Insert(0, New ListEditItem("General SAPA Question", "0"))

        If Not (Page.IsPostBack Or Page.IsCallback) Then
            If Request.QueryString("ComID") IsNot Nothing Then
                Dim ComID As Integer = 0
                Try
                    Dim selCom As Integer = CInt(Request.QueryString("ComID"))
                    cb.SelectedIndex = cb.Items.FindByValue(selCom).Index
                Catch ex As Exception
                    ' don't log
                    cb.SelectedIndex = 0
                End Try
            Else
                cb.SelectedIndex = 0
            End If
        End If
    End Sub

    Private Sub odsQuestion_Inserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceStatusEventArgs) Handles odsQuestion.Inserted
        If e.Exception IsNot Nothing Then
            JavaHelper.Alert.Show(e.Exception.Message)
            e.ExceptionHandled = True
        Else
            Notify()
            JavaHelper.Alert.Show("Your question was submitted to SAPA. You will be notified via email and this site when SAPA has posted an answer. Thank you for your participation.")
        End If
    End Sub

    Private Sub odsQuestion_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs) Handles odsQuestion.Inserting
        e.InputParameters("Questioner") = CurrentSapaUser.Users(0).EmpNo
        _newRowID = Guid.NewGuid
        e.InputParameters("RowGuid") = _newRowID
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        If Page.IsValid And ddlCommittee.SelectedIndex > -1 Then
            odsQuestion.Insert()
        End If
    End Sub

Open in new window

0
Comment
Question by:dacIT
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 8

Expert Comment

by:Mohit Vijay
ID: 33688581
Let me assume, you have name of dropdown as ddl1, so

ddl1.selectedItem.value will give you value part and
ddl1.selectedItem.text will give you text part.
0
 
LVL 3

Expert Comment

by:vusov
ID: 33690622
Use SelectedValue property. So will have this code
<asp:ControlParameter ControlID="ddlCommittee" Name="CommitteeId" 
                PropertyName="SelectedValue"  />

Open in new window

0
 
LVL 7

Author Comment

by:dacIT
ID: 33693286
Thanks, but as you can see from the posted code, that's what I'm doing.
0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
LVL 7

Author Comment

by:dacIT
ID: 33717584
Whoops. I guess my code DOESN'T have the selectedvalue in the markup, it was in there when I tested it however. I just tested again and it's sending NULL as the parameter value in the ODS even though the DDL does have a value selected. I'm stumped. This should be pretty straight forward.
0
 
LVL 7

Author Comment

by:dacIT
ID: 33717625
Actually, it is in there, it's the control parameter in the ODS insert section. Still doesn't work.
0
 
LVL 7

Accepted Solution

by:
dacIT earned 0 total points
ID: 33717857
Well, I figured out the problem. It was the viewstate was in fact disabled in the inherited base page. Once I reenabled it, everything worked as I would expect. Thanks for everyone's input.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question