Display information on page2 that refers to information from Page 1

Last post 05-16-2008 8:23 AM by ahlaj77. 7 replies.

Sort Posts:

  • Confused [8-)] Display information on page2 that refers to information from Page 1

    05-12-2008, 11:34 AM
    • Loading...
    • ahlaj77
    • Joined on 03-18-2008, 2:15 PM
    • usa
    • Posts 98

    Hello there,

    On my HomePage.aspx I have a gridview that displays several columns (Book ID, BookName, AuthorName). When I click on the "View" link button on the gridview (its on each row) it takes me to a page which displays a each of these in a textbox (using session variables). As you can see below in my Book table I have another column called "Book Review" but i do not want this displayed on my gridview on Homepage.aspx.

    However, I would like to display "Book Review" on "ViewBookReview.aspx" page in a textbox. How would I go about doing this? Thank yoU!! If you need me to further explain I can do that as well.

    ***Book***
    Book ID
    BookName
    BookReview

    ***Author***
    BookID
    AuthorName
     

    "People will mainly remember you for who you are, not what you were a part of"
  • Re: Display information on page2 that refers to information from Page 1

    05-12-2008, 12:13 PM
    • Loading...
    • SrDhUS
    • Joined on 12-28-2004, 10:17 AM
    • IL,Chicago
    • Posts 108

    Option 1:

    If you have the keys once you get to ViewBookReview.aspx, you can make a DB call and fetch the “Book Review” again.

     

    Option2:

     If not, you can set Visible=False so that the “Book Review” is not visible in the GridView. But you can still pass that to the ViewBookReview.aspx just like you pass all the other values.

     

    Please remember to click “Mark as Answer” on the post that helps you
  • Re: Display information on page2 that refers to information from Page 1

    05-12-2008, 1:00 PM
    • Loading...
    • ahlaj77
    • Joined on 03-18-2008, 2:15 PM
    • usa
    • Posts 98

    SrDhUS:

    Option 1:

    If you have the keys once you get to ViewBookReview.aspx, you can make a DB call and fetch the “Book Review” again.

    How would I go about doing this? Thank you so much!! BTW I am coding in C# Cool I am passing the keys.

    **This is the name of my connection from WebConfig**

     <connectionStrings>

    <add name="BooksConnectionString" connectionString="Data Source=server01;Initial Catalog=Books;Integrated Security=True"

    providerName="System.Data.SqlClient" />

    </connectionStrings>

     

    "People will mainly remember you for who you are, not what you were a part of"
  • Huh? [:^)] Re: Display information on page2 that refers to information from Page 1

    05-13-2008, 9:33 AM
    • Loading...
    • ahlaj77
    • Joined on 03-18-2008, 2:15 PM
    • usa
    • Posts 98

    ~*~Should I use a stored procedure to call or what not?~*~ :) Please help! Huh?

    "People will mainly remember you for who you are, not what you were a part of"
  • Re: Display information on page2 that refers to information from Page 1

    05-13-2008, 10:01 AM
    • Loading...
    • SrDhUS
    • Joined on 12-28-2004, 10:17 AM
    • IL,Chicago
    • Posts 108

    You can use a stored procedure or you can do a SELECT from the client: 

    Check this for some C# examples: http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson03.aspx

    Please remember to click “Mark as Answer” on the post that helps you
  • Re: Display information on page2 that refers to information from Page 1

    05-14-2008, 9:19 AM
    • Loading...
    • ahlaj77
    • Joined on 03-18-2008, 2:15 PM
    • usa
    • Posts 98

    Do you have an idea (or example) how to set up the stored procedure where it'll know what BookID is being passed to the 2nd page...that will allow that particular review for that particular bookID to display in the textbox?

     

    **Thank u!!**

    "People will mainly remember you for who you are, not what you were a part of"
  • Re: Display information on page2 that refers to information from Page 1

    05-15-2008, 11:57 PM
    Answer

    Hi ahlaj77,

    You can pass the BookID to the second page through query string. For this scenario, we can implement by setting the “View” hyperlink dynamicaly in code behind. For your reference, please refer to the following code:

    ************ HomePage.aspx.cs **************
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"
                onrowdatabound="GridView1_RowDataBound">
            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:HyperLink ID="HyperLink1" Target="_blank" Text="View" runat="server"></asp:HyperLink>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField HeaderText="ID" DataField="ID" />
                <asp:BoundField HeaderText="Name" DataField="Name" />
            </Columns>
            </asp:GridView>
        </div>
        </form>
    </body>
    </html>

    ************ HomePage.aspx.cs **************
        protected void Page_Load(object sender, EventArgs e)
        {
            DataTable table = new DataTable();
            if (!Page.IsPostBack)
            {
                table.Columns.Add("ID",typeof(int));
                table.Columns.Add("Name", typeof(string));
                table.Rows.Add(1,"abc");
                table.Rows.Add(2, "efg");
                GridView1.DataSource = table;
                GridView1.DataBind();
            }
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                HyperLink link = (HyperLink)e.Row.FindControl("HyperLink1");
                link.NavigateUrl = string.Format("http://YourWebSite/ViewBookReview.aspx?BookID={0}",e.Row.Cells[1].Text);
            }
        }

    Then in ViewBookReview.aspx we can get the BookID and pass it to stored proecedure. You can see detailed information about how to pass variables between pages using query string from the following link:

    Passing variables between pages using QueryString
    http://www.codeproject.com/KB/aspnet/QueryString.aspx

    Sincerely,
    Benson Yu
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help. This can be beneficial to other community members reading the thread.
  • Re: Display information on page2 that refers to information from Page 1

    05-16-2008, 8:23 AM
    • Loading...
    • ahlaj77
    • Joined on 03-18-2008, 2:15 PM
    • usa
    • Posts 98

    thanks I will take a look at it :)

    "People will mainly remember you for who you are, not what you were a part of"
Page 1 of 1 (8 items)