Click here to Skip to main content
16,021,041 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two pages. Grid view page and profile page.

In the first page, there is one databound field(id), and the hyperlink(profile).

If i click the hyperlink i can view the full staff details in separate web page(using "id" as a session)

Plz help me...

Thank you in advance
Posted

I am assuming you need an example of Grid View and Details View. Please have a look at following link:
GridView and Details View[^]
http://msdn.microsoft.com/en-us/library/ms972814.aspx[^]
GridView-DetailsView (Master/Detail) Control[^]
 
Share this answer
 
Default.aspx
__________________________

XML
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
        onrowcommand="GridView1_RowCommand">
        <Columns>
            <asp:BoundField DataField="id" HeaderText="id" />
            <asp:BoundField DataField="name" HeaderText="name" />
            <asp:BoundField DataField="address" HeaderText="address" />
            <asp:TemplateField>
            <ItemTemplate>
            <asp:LinkButton ID="XXXXX" runat="server" Text="NEW PAGE" CommandName="AA" CommandArgument='<%#Eval("id") %>' />


            </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>


Default.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.Data;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            BindGridview();
    }
    protected void BindGridview()
    {
        using (SqlConnection con = new SqlConnection("--------"))
        {
            con.Open();
            SqlCommand cmd = new SqlCommand("Select * FROM TEST", con);
            SqlDataReader dr = cmd.ExecuteReader();
            GridView1.DataSource = dr;
            GridView1.DataBind();
            con.Close();
        }
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "AA")
        {
            string id = e.CommandArgument.ToString();
            //if u want to use querystring//
            Server.Transfer("Default2.aspx?id=" + id);
            // if u want to use session//
            // Session["id"] = id.ToString();
            // Server.Transfer("Default2.aspx");
            
        }

    }
}



Default2.aspx.cs
_____________________________
C#
protected void Page_Load(object sender, EventArgs e)
    {
        string id=Request.QueryString["id"];//for query string
        //string id1 = Session["id"].ToString();//for session
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900