Click here to Skip to main content
15,905,616 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

i have a staff details in gridview ,

when i click the hyperlink in the row ,which im using staff id as hyperlink,

that corresponding row data will pass to next page ,

pls help anybody to me.....
Posted

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>


code
_________________
C#
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();
            Server.Transfer("Default2.aspx?id=" + id);
        }

    }
}
 
Share this answer
 
v2
Comments
Raje_ 11-Feb-13 8:32am    
My +5
try this :

you may use Template field of grid view .

<Columns>

       <asp:TemplateField HeaderText="Path" Visible="false">
       <ItemTemplate>
           <asp:Label ID="Label1" runat="server" Text='<%#Eval("ID")%>' ></asp:Label>
       </ItemTemplate>
       </asp:TemplateField>




here ID is the Unique key for each data.

now,

use ROW data Command event of Grid.

   protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        c.setcon();
        if(e.CommandName.Equals("link"))
        {
            int index = System.Convert.ToInt32(e.CommandArgument); // find the index of row that you clicked
                Label l1 = (Label)GridView1.Rows[index].FindControl("Label1"); // here "Label1" is the label name of your ID.

     //     now use query string to redirect next page

         response.redirect("xyz.aspx?data_id='"+l1.toString()+"'");
      

         }
   }
// and get Data_id from next page



this will help you...
if not , please post it what error come or your problem.

Mitesh
 
Share this answer
 
v2
Hello Read It :

Using Hyperlink columns in GridView[^]


Thanks
 
Share this answer
 
v2
Hi Jaison Joe,

use the Session like this

C#
Session["staffdetails"] = dtStaffDetails;


pass id from hyperlink as query string
on the next page
C#
DataTable dtStaffDetails = (DataTable)Session["staffdetails"];

filter data table based on the ID(which you will get by query string)

C#
dtStaffDetails.Select("StaffID"); // pass here your query string id as StaffID
 
Share this answer
 
Comments
Jaison Joe 11-Feb-13 23:49pm    
Thank u for ur response...

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

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

Plz help me...
OPees 12-Feb-13 0:21am    
Hi Jaison Joe,

No, you cant view the full staff details, if you are passing only id in the session.
i suggest you pass whole datatable/dataset in session which you bind for gridview as data source and id on query string, on the next page you can filter your datatable/dataset based on id(which is in query string)
Try this, it may help you.....
<itemtemplate>
      <asp:hyperlink id="hlingView" runat="server" text="View" navigateurl='<%# "yourURLtoRedirect?parameter=" + Eval("ID")%>'  />
                                        
</itemtemplate>


if it help full then accept the solution and rate it
 
Share this answer
 
v3

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