0 Replies - 4840 Views - Last Post: 23 March 2012 - 01:06 PM

#1 belgailian  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 23-March 12

gridview ,dropdownlist and 2 data sources issue

Posted 23 March 2012 - 01:06 PM

ok, im woking on the sports pro project for school. am realy frustrated with the gridview and using more then one data source with it. im trying to display specific information based on a dropdownlist selection. i can get the data to load in to a class, but for some reason i fail to see, i cant put it in the gridview. it keeps displaying the whole data base.
this is the aspx code
<%@ Page Language="vb" AutoEventWireup="false" MasterPageFile="~/sportspro.Master" CodeBehind="CustomerIncidentDisplay.aspx.vb" Inherits="sportspro.CustomerIncidentDisplay" 
    title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
 </asp:Content>
 
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
 
           
         
 </asp:Content>
<asp:Content ID="Content3" runat="server" contentplaceholderid="Main">
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
        ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" 
        
        SelectCommand="SELECT [CustomerID], [Name] FROM [Customers] WHERE ([CustomerID] = ?)">
        <SelectParameters>
            <asp:ControlParameter ControlID="incidentsDDL" Name="CustomerID" 
                PropertyName="SelectedValue" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>
           choose a customer:         
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
        ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" 
        SelectCommand="SELECT Customers.CustomerID, Incidents.IncidentID, Technicians.TechID, Products.Name, 
        Incidents.DateOpened, Incidents.DateClosed, Incidents.Description FROM (((Customers INNER JOIN Incidents ON Customers.CustomerID = Incidents.CustomerID) 
        INNER JOIN Products ON Incidents.ProductCode = Products.ProductCode) INNER JOIN Technicians ON Incidents.TechID = Technicians.TechID) ">
    </asp:SqlDataSource>
    
    <asp:DropDownList ID="incidentsDDL" runat="server" 
        DataSourceID="SqlDataSource1" DataTextField="Name" 
        DataValueField="CustomerID">
    </asp:DropDownList>
    <asp:GridView ID="IncidentsGridView" runat="server" AutoGenerateColumns="False" 
        DataSourceID="SqlDataSource2" AllowSorting="True">
        <Columns>
            <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" 
                SortExpression="CustomerID" InsertVisible="False" />
            <asp:BoundField DataField="IncidentID" HeaderText="IncidentID" 
                SortExpression="IncidentID" InsertVisible="False" />
            <asp:BoundField DataField="TechID" HeaderText="TechID" 
                SortExpression="TechID" InsertVisible="False" />
            <asp:BoundField DataField="Name" HeaderText="Name" 
                SortExpression="Name" />
            <asp:BoundField DataField="DateOpened" HeaderText="DateOpened" 
                SortExpression="DateOpened" />
            <asp:BoundField DataField="DateClosed" HeaderText="DateClosed" 
                SortExpression="DateClosed" />
            <asp:BoundField DataField="Description" HeaderText="Description" 
                SortExpression="Description" />
        </Columns>
    </asp:GridView>

    </asp:Content>


this is the vb
Imports System.Data.SqlClient

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

    Public selectedincident As incidents
    Private IncidentDisplay As Boolean
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim customerID As String = incidentsDDL.SelectedValue
        If Not IsPostBack Then
            incidentsDDL.DataBind()

            selectedincident = Me.getselectedincident()

            IncidentsGridView.DataSourceID = IncidentDisplay
        End If
        




    End Sub
    Private Function Getincident() As SortedList
        If Session("incidents") Is Nothing Then
            Session.Add("incidentsr", New SortedList)
        End If
        Return CType(Session("incidents"), SortedList)

    End Function

    Protected Sub incidentsDDL_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles incidentsDDL.SelectedIndexChanged
    End Sub
    Private Function getselectedincident() As incidents
        'load the selected incident in to incidents from DB
        Dim dv As DataView = CType(SqlDataSource2.Select(DataSourceSelectArguments.Empty), DataView)
        Dim selectedincident As New incidents
        Dim incidentRow As DataRowView = dv(0)
        Dim customerID As String = incidentsDDL.SelectedValue

        selectedincident.customerId = incidentRow("CustomerID").ToString
        selectedincident.incidentId = incidentRow("IncidentId").ToString
        selectedincident.dateOpened = incidentRow("DateOpened").ToString
        selectedincident.dateClosed = incidentRow("DateClosed").ToString
        'selectedincident.techId = dv("TechID").ToString

        Return selectedincident
    End Function
End Class


also a class file
Public Class incidents
    Public incidentId As String
    Public customerId As String
    Public productCode As String
    Public techId As Integer
    Public dateOpened As String
    Public dateClosed As String
    ' Public title As String
    Public discription As String

    Public Function incidentDisplay() As String
        Dim Selectedincident As New incidents
        Selectedincident = (System.Web.HttpContext.Current.Session("CustomerIncidentDisplay"))
        Return Selectedincident.customerId + ": " + Selectedincident.dateClosed + ", " + Selectedincident.dateOpened + "," + Selectedincident.discription + "," + Selectedincident.productCode + "," + Selectedincident.incidentId

    End Function
End Class



Is This A Good Question/Topic? 0
  • +

Page 1 of 1