troubleshooting Question

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

Avatar of cesemj
cesemj asked on
.NET ProgrammingASP.NET
9 Comments2 Solutions280 ViewsLast Modified:
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>
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 9 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros