Как мога да навигирам до страницата book_detail.aspx с един атрибут, който ще се съхранява в променливата на низ на заявка

Създавам страница с подробности за книгата, която показва снимки на корицата на книгата, заглавие на книгата, автор, isbn номер и т.н.

book_all.aspx

<%@ Page Title="" Language="C#" MasterPageFile="~/book.master" AutoEventWireup="true" CodeFile="book_all.aspx.cs" Inherits="book_all" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <div>
        <asp:TextBox ID="res" runat="server"></asp:TextBox>
        <br />
        <br />
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
            AutoGenerateColumns="False" BackColor="#DEBA84" BorderColor="#DEBA84" 
            BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2" 
            DataKeyNames="isbn" DataSourceID="SqlDataSourceAll" PageSize="4">
            <Columns>
                <asp:TemplateField HeaderText="cover_pic" SortExpression="cover_pic">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("cover_pic") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Image ID="Image1" runat="server" ImageUrl='<%# Bind("cover_pic") %>' Height="125px" Width="100px" />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="isbn" HeaderText="isbn" ReadOnly="True" 
                    SortExpression="isbn" />
                <asp:BoundField DataField="title" HeaderText="title" SortExpression="title" />
                <asp:BoundField DataField="author" HeaderText="author" 
                    SortExpression="author" />
                <asp:BoundField DataField="edition" HeaderText="edition" 
                    SortExpression="edition" />
                <asp:BoundField DataField="publisher" HeaderText="publisher" 
                    SortExpression="publisher" />
                <asp:BoundField DataField="type" HeaderText="type" SortExpression="type" />
                <asp:BoundField DataField="price" HeaderText="price" SortExpression="price" />
                <asp:BoundField DataField="qty" HeaderText="qty" SortExpression="qty" />
                <asp:BoundField DataField="available" HeaderText="available" 
                    SortExpression="available" />
                <asp:TemplateField>
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("cover_pic") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:LinkButton ID="detail" runat="server" Text="Details" OnClick="detail_click"></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
            <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
            <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
            <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
            <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
            <SortedAscendingCellStyle BackColor="#FFF1D4" />
            <SortedAscendingHeaderStyle BackColor="#B95C30" />
            <SortedDescendingCellStyle BackColor="#F1E5CE" />
            <SortedDescendingHeaderStyle BackColor="#93451F" />
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSourceAll" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
            SelectCommand="SELECT * FROM [book_info]"></asp:SqlDataSource>        
    </div>
</asp:Content>

Искам да навигирам в страницата book_detail.aspx само с един кортеж, чийто бутон за подробности ще бъде щракване (подробност за името на бутона за връзка)

Това е cs кодът на предишната aspx страница.

book_all.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data.SqlClient;

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

    }
    protected void detail_click(object sender, EventArgs e)
    {
        Response.Redirect("book_detail.aspx?IsbnNo="+GridView1.FindControl("isbn").ToString());

    }
}

person user3535626    schedule 30.04.2014    source източник
comment
ще трябва да създадете персонализирана колона за Преглед на подробности за книгата във вашия мрежов изглед и с помощта на EventArgs можете да навигирате до страницата с подробности с низ за заявка isbnno.   -  person Murtaza    schedule 30.04.2014


Отговори (1)


Надявам се, че примерът по-долу ще ви помогне. Това е абстракт от един от моите проекти, който прави същото, от което се нуждаете.

Като схема трябва да изпълните следните стъпки:

  • В GridView създайте TemplateField, който съдържа връзката за навигация към друга страница (linkButton или imageButton или Button)
  • Задайте свойства CommandArgument и CommandName за тази контрола на връзката
  • Във вашия C# код обработете събитието RowCommand на gridView
  • Въз основа на commandName и commandArgument отидете до другата страница.

.ASPX

<asp:GridView ID="gv" runat="server" AutoGenerateColumns="False" OnRowCommand="gv_RowCommand"
    EmptyDataText="No record found" Width="1000px">
    <Columns>
        <asp:BoundField DataField="ISBN" />
        <asp:BoundField DataField="Title" HeaderText="Title"/>
        .
        .
        .
        .
        .
        <asp:TemplateField HeaderText="Actions">
            <ItemTemplate>
                <asp:LinkButton ID="lnkEdit" runat="server" CommandArgument='<%# Eval("ISBN") %>'
                    CommandName="viewDetails">View Details</asp:LinkButton>             </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

В горния код основните неща, които трябва да видите, са настройката на свойствата CommandArgument и CommandName на LinkButton. Те ще бъдат използвани в .cs кода

.ASPX.CS

protected void gv_RowCommand(object sender, GridViewCommandEventArgs e)
{
    // ensure that commandArgument is not null, which may happen when someone tries to hack the page
    string isbn = e.CommandArgument.ToString();
    if (string.IsNullOrEmpty(uid))
    {
        // error message, someone has tried to hack the web page
        return;
    }

    if (e.CommandName == "viewDetails")
    {
        Response.Redirect("book-details.aspx?isbn=" + isbn);
        return;
    }

    // handle any other command that may be there (like delete, edit, etc)
}
person Manish Dalal    schedule 30.04.2014
comment
Благодаря ти много Маниш - person user3535626; 30.04.2014