• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 268
  • Last Modified:

get value from drop down list an pass to a detail page

Hi,
I created a form with dropdown list.  I woul like to get the selected value and pass the values to a detail page that will show the data results.  I am having a problem collecting the values to pass to the detail page like a where query.  Please help.

Reference
Also, I have manually tested the query that the detail page will use in sql server 2005 using the values that I would like to pass from the drop down list and the test works fine.

SELECT     dbo.cbmPart.Class, dbo.WorkOrders.ESD, dbo.WorkOrders.Priority, dbo.WorkOrders.PrimTech,
                      dbo.Visits.DateEntered
FROM         dbo.WorkOrders INNER JOIN
                      dbo.Visits ON dbo.WorkOrders.VisitID = dbo.Visits.VisitID INNER JOIN
                      dbo.Ships ON dbo.Visits.ShipID = dbo.Ships.RecordID INNER JOIN
                      dbo.cbmPart ON dbo.Ships.ShipClassID = dbo.cbmPart.RecordID
WHERE     (dbo.cbmPart.Class = 999) AND (dbo.WorkOrders.PrimTech = 'OutdoorUnit') AND (dbo.WorkOrders.ESD = 'AIR-Belt')
                      AND (dbo.WorkOrders.Priority = '1') AND (dbo.Visits.DateEntered BETWEEN CONVERT(DATETIME, '2008-01-01 00:00:00', 102) AND
                      CONVERT(DATETIME, '2008-05-01 00:00:00', 102))
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="rptTest.aspx.vb" Inherits="test.Test" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body style="text-align: center">
    <form id="form1" runat="server">
    <div style="text-align: center">
        Part
        <asp:DropDownList ID="cbmPart" runat="server" AutoPostBack="True" DataSourceID="dscbmPart"
            DataTextField="Class" DataValueField="RecordID">
        </asp:DropDownList>Technology
        <asp:DropDownList ID="cbmTech" runat="server" DataSourceID="SqlDataSource1" DataTextField="Technology"
            DataValueField="Technology" AutoPostBack="True">
        </asp:DropDownList>System
        <asp:DropDownList ID="CbmSystem" runat="server" AutoPostBack="True" DataSourceID="dsCbmSystem"
            DataTextField="ESD" DataValueField="ESD">
        </asp:DropDownList>Priority
        <asp:DropDownList ID="CbmPrity" runat="server" DataSourceID="dsCbmPrity" DataTextField="Priority"
            DataValueField="Priority">
        </asp:DropDownList>&nbsp;<br />
        <br />
        Start Date
        <asp:TextBox ID="tbxStartDate" runat="server"></asp:TextBox>
        &nbsp;<asp:ImageButton ID="btnCalendar1" runat="server" ImageUrl="~/Images/picCalendar.jpg" />
        &amp; End Date
        <asp:TextBox ID="tbxEndDate" runat="server"></asp:TextBox>
        <asp:ImageButton ID="btnCalendar2" runat="server" ImageUrl="~/Images/picCalendar.jpg" />
        <br />
        <br />
        <asp:LinkButton ID="lbtnDisplayRecords" runat="server">Display Records</asp:LinkButton><br />
        <br />
        <asp:SqlDataSource ID="dsCbmPrity" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
            SelectCommand="SELECT [ESD], [Priority] FROM [tblCbmPrity] WHERE ([ESD] = @ESD)">
            <SelectParameters>
                <asp:ControlParameter ControlID="CbmSystem" Name="ESD" PropertyName="SelectedValue"
                    Type="String" />
            </SelectParameters>
        </asp:SqlDataSource>
        <asp:SqlDataSource ID="dsCbmSystem" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
            SelectCommand="SELECT [ESD], [PrimTech] FROM [tblCbmSystem] WHERE ([PrimTech] = @PrimTech)">
            <SelectParameters>
                <asp:ControlParameter ControlID="cbmTech" Name="PrimTech" PropertyName="SelectedValue"
                    Type="String" />
            </SelectParameters>
        </asp:SqlDataSource>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
            SelectCommand="SELECT [Technology], [RecordID] FROM [tblDDlTech] WHERE ([RecordID] = @RecordID)">
            <SelectParameters>
                <asp:ControlParameter ControlID="cbmPart" Name="RecordID" PropertyName="SelectedValue"
                    Type="String" />
            </SelectParameters>
        </asp:SqlDataSource>
        <asp:SqlDataSource ID="dscbmPart" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
            SelectCommand="SELECT [RecordID], [Class] FROM [ShipClasses]"></asp:SqlDataSource>
        <cc1:CalendarExtender ID="CalendarExtender1" runat="server" PopupButtonID="btnCalendar1"
            TargetControlID="tbxStartDate">
        </cc1:CalendarExtender>
    
    </div>
        <cc1:CalendarExtender ID="CalendarExtender2" runat="server" PopupButtonID="btnCalendar2"
            TargetControlID="tbxEndDate">
        </cc1:CalendarExtender>
        <cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
        </cc1:ToolkitScriptManager>
    </form>
</body>
</html>

***************** Code Behind Page *************************
Imports System.Data
Imports System.Data.Common
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.Data.SqlClient
Imports Microsoft.VisualBasic

Partial Public Class rptTest
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub lbtnDisplayRecords_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbtnDisplayRecords.Click

        Dim cbmPart As DropDownList
        'cbmPart value=Request.Form[cbmPart].SelectedValue];
        cbmPart.SelectedValue.Contains(cbmPart)  **' Error msg cannot be converted to string

        Dim cbmTech As DropDownList
        cbmTech.SelectedValue.Contains(cbmTech)

        Dim CbmSystem As DropDownList
        CbmSystem.SelectedValue.Contains(CbmSystem)

        Dim CbmPrity As DropDownList
        CbmPrity.SelectedValue.Contains(CbmPrity)

        Dim tbxStartDate As DropDownList
        tbxStartDate.SelectedValue.Contains(tbxStartDate)

        Dim tbxEndDate As DropDownList
        tbxEndDate.SelectedValue.Contains(tbxEndDate)

        'Dim passdata As New StringCollection

'Does Not Work
        ' get the value from each combo box and two date range fields
        '        Dim cbmPart As Integer = _
        'Convert.ToInt32()
        'PassData.Add(cbmPart.ToString)


        'Session("passdata") = passdata
        'Response.Redirect("~/Members/Test/rptTestDetail.aspx", True)
    End Sub
End Class

***************************Detail Page ******************************
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="rptSSDCLDetail.aspx.vb" Inherits="test.rptTestDetail" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title> Test</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        Detail Page<br />
        <br />
        <asp:GridView ID="GridView1" runat="server">
        </asp:GridView>
    
    </div>
    </form>
</body>
</html>

Open in new window

0
cesemj
Asked:
cesemj
  • 5
  • 3
2 Solutions
 
rajeeshmcaCommented:
Hi cesemi,

what does it happen when you take the dropdown.SelectedValue property
0
 
Craig WagnerSoftware ArchitectCommented:
My comments assume that the code you posted is complete.

First, turn off AutoPostBack on your DropDownLists. You're not handling the SelectedIndexChanged events anyway, so there's no reason to post back to the server each time the user makes a new selection.

Second, I'm not sure what you're trying to do with the following code:

cbmTech.SelectedValue.Contains(cbmTech)

You're asking if the SelectedValue (a string) of the DropDownList (cbmTech) contains the DropDownList control itself? That doesn't make any sense. If you want the currently selected value, just use:

cbmTech.SelectedValue

That gets you a string representing the value selected in the DropDownList.

Finally, I don't understand your commented-out code at the bottom. In particular, you have a "does not work" comment. What does not work? What error are you getting?

Basically, your code-behind should look something like below.

I hate to say this, but you need to spend some time in the documentation. TextBoxes have a Text property, not a SelectedValue property.
Dim passdata As New StringCollection

passdata.Add( cbmPart.SelectedValue )
passdata.Add( cbmTech.SelectedValue )
passdata.Add( cbmSystem.SelectedValue )
passdata.Add( cbmPrity.SelectedValue )
passdata.Add( tbxStartDate.Text)
passdata.Add( tbxEndDate.Text )

Session("passdata") = passdata
Response.Redirect("~/Members/Test/rptTestDetail.aspx", True)

Open in new window

0
 
cesemjAuthor Commented:
Thank you and sorry for the confusion with my documentation,

Please forgive my documentations skills:  I have been spinning my wheels researching different topics and trying different lines of code that really did not help except make me spin more.

For example:
1) I read an article about geeting the value from a combobox and it said use: string value=Request.Form[DropDownList1.UniqueId]; so I tried different variations  cbmTech.SelectedValue.Contains(cbmTech). I know bad.

2) I put 'Does Not Work for this section because I screwed up and until the above section was fixed the bottom would not work.
  ' get the value from each combo box and two date range fields
        '        Dim cbmPart As Integer = _
        'Convert.ToInt32()
        'PassData.Add(cbmPart.ToString)

3) I will turn off AutoPostBack on the DropDownLists, I was making cascading list the You're not handling the SelectedIndexChanged

I will let you know what happens.

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
rajeeshmcaCommented:
what are u getting when u just use the cbmTech.SelectedValue;
0
 
cesemjAuthor Commented:
Hi and thank you again,

The detail page opens but, the records are not being filtered, can you tell me what am I doing wrong? I have attached the detail page info.

I listed the select statement before I changed it to SelectCommand="****". I changed it to SelectCommand="****" because I added the Selecting event behind the page to read the passdata.  I might have not performed this step correctly, What do think?
 
SelectCommand="SELECT [RecordID], [Class], [PartName], [OptionName], [ESD], [Priority], [PrimTech], [DateEntered] FROM [qryDetailTest]"></asp:SqlDataSource>

Detail Page 
***********
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="rptTestDetail.aspx.aspx.vb" Inherits="test.rptTestDetail.aspx" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>AGIS (Test)</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        Detail Page<br />
        <br />
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" Width="593px">
            <Columns>
                <asp:BoundField DataField="Class" HeaderText="Class" SortExpression="Class" />
                <asp:BoundField DataField="ESD" HeaderText="System Name" SortExpression="ESD" />
                <asp:BoundField DataField="Priority" HeaderText="Priority" SortExpression="Priority" />
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
            SelectCommand="****"></asp:SqlDataSource>
        &nbsp;
    
    </div>
    </form>
</body>
</html>

************* code behind rptTestDetail.aspx*****************************
Imports System.Data.Common
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.Data.SqlClient
Imports Microsoft.VisualBasic

Partial Public Class rptTestDetail
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub SqlDataSource1_Selecting(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs) Handles SqlDataSource1.Selecting
        ' initial query 
        Dim Query As String = "select * from qryDetailTest "
        ' get the selected data from the first page 
        Dim passdata As StringCollection = Session("passdata")
        

        'I'm setting SqlDataSource1, so that it will get executed and the gridview will display the data. 
        e.Command.CommandText = Query

    End Sub
End Class

Open in new window

0
 
cesemjAuthor Commented:
I am not getting any error with the cbmTech.selected value now.  I think my problem is now with the detail page reading the data because it just open up the gridview displaying all records form the query.
0
 
cesemjAuthor Commented:
Thank you & sorry rof the delay. I have been out sick with the bad case of flu
0
 
cesemjAuthor Commented:
0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now