2 Replies - 1070 Views - Last Post: 03 July 2015 - 10:21 PM Rate Topic: -----

#1 develauper   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 10-February 15

Query String Gridview Redirect

Posted 24 June 2015 - 06:55 PM

I am creating a website to basically act as a movie database. I have 4 tables: Customer, Movie, Rental, Genre. I am trying to have a page called "Display Customer" show a customers information, I have successfully done so in a gridview and I have enabled select. I want to be able to click select next to a customers name and see all the movies they have rented. This involves joining the customer table to the rental table and then rental to movie. I have been able to click select and be directed to the page I want, however for each customer it shows all the movies rented by every customer(not in particular by them). So for a customer that has never rented a movie it will show the movies rented by every other customer and for all the other customers it shows the same data. I think my issue is with my gridview for the rental page, I dont think it is referencing my query string but I am not sure how to make it join all the tables together and reference the query string.

Here is my code for the "Display Customer"
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Exam2d.aspx.cs" Inherits="Default5" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1" DataTextField="CUST_name" DataValueField="CUST_name">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [customer]"></asp:SqlDataSource>
    <asp:Button ID="Button1" runat="server" Text="Select" />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="CUST_ssn" DataSourceID="SqlDataSource2" onselectedIndexChanged="GridView1_SelectedIndexChanged">
    <Columns>
        <asp:CommandField ShowSelectButton="True" />
        <asp:BoundField DataField="CUST_ssn" HeaderText="SSN" ReadOnly="True" SortExpression="CUST_ssn" />
        <asp:BoundField DataField="CUST_name" HeaderText="Name" SortExpression="CUST_name" />
        <asp:BoundField DataField="CUST_dob" HeaderText="Date of Birth" SortExpression="CUST_dob" />
        <asp:BoundField DataField="CUST_memberdate" HeaderText="Member Date" SortExpression="CUST_memberdate" />
    </Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [customer] WHERE ([CUST_name] = @CUST_name)">
    <SelectParameters>
        <asp:ControlParameter ControlID="DropDownList1" Name="CUST_name" PropertyName="SelectedValue" Type="String" />
    </SelectParameters>
</asp:SqlDataSource>
</asp:Content>






Here is the code behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default5 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        string ans;
        ans = GridView1.SelectedValue.ToString();

        Response.Redirect("http://localhost:4116/Exam2/Exam2e.aspx?myans="+ans);

    }
}




Here is the code for the Rental Page:
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Exam2e.aspx.cs" Inherits="Default2" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="MOV_code" DataSourceID="SqlDataSource1" onselectedIndexChanged="GridView1_SelectedIndexChanged">
        <Columns>
            <asp:BoundField DataField="MOV_code" HeaderText="MOV_code" ReadOnly="True" SortExpression="MOV_code" />
            <asp:BoundField DataField="MOV_title" HeaderText="MOV_title" SortExpression="MOV_title" />
            <asp:BoundField DataField="MOV_releasedate" HeaderText="MOV_releasedate" SortExpression="MOV_releasedate" />
            <asp:BoundField DataField="MOV_duration" HeaderText="MOV_duration" SortExpression="MOV_duration" />
            <asp:BoundField DataField="MOV_price" HeaderText="MOV_price" SortExpression="MOV_price" />
            <asp:BoundField DataField="MOV_genre" HeaderText="MOV_genre" SortExpression="MOV_genre" />
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT Movie.MOV_code, Movie.MOV_title, Movie.MOV_releasedate, Movie.MOV_duration, Movie.MOV_price, Movie.MOV_genre FROM customer INNER JOIN rental ON customer.CUST_ssn = rental.RENT_customer INNER JOIN Movie ON rental.RENT_movie = Movie.MOV_code "></asp:SqlDataSource>
</asp:Content>





Here is the code behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}



Is This A Good Question/Topic? 0
  • +

Replies To: Query String Gridview Redirect

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15427
  • View blog
  • Posts: 61,802
  • Joined: 12-June 08

Re: Query String Gridview Redirect

Posted 25 June 2015 - 07:06 AM

I would advocate that you pass the customer's ID into the WHERE clause for your query with the joins.
Was This Post Helpful? 0
  • +
  • -

#3 zinist   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 18
  • Joined: 25-June 15

Re: Query String Gridview Redirect

Posted 03 July 2015 - 10:21 PM

Hi,
Yes i am agree with modi123_1 just pass the custid in where clause then you would get expected result
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1