Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
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 10-Feb-13 23:53pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

<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
_________________
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);
        }
 
    }
}
  Permalink  
v2
Comments
Raje_ at 11-Feb-13 8:32am
   
My +5
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Hi Jaison Joe,
 
use the Session like this
 
Session["staffdetails"] = dtStaffDetails;
 
pass id from hyperlink as query string
on the next page
 DataTable dtStaffDetails = (DataTable)Session["staffdetails"];  
filter data table based on the ID(which you will get by query string)
 
dtStaffDetails.Select("StaffID"); // pass here your query string id as StaffID
  Permalink  
Comments
Jaison Joe at 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 at 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)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

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
  Permalink  
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hello Read It :
 
Using Hyperlink columns in GridView[^]
 

Thanks
  Permalink  
v2

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



Advertise | Privacy | Mobile
Web04 | 2.8.140926.1 | Last Updated 11 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100