Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear sirs,

I have taken hyperlink inside the gridview.how i want to pass one value from one page to another by clicking hyperlink which is inside the gridview.Coding in design page is

XML
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
            DataKeyNames="id" DataSourceID="SqlDataSource1"
            onselectedindexchanged="GridView1_SelectedIndexChanged">
            <Columns>
                <asp:BoundField DataField="id" HeaderText="id" InsertVisible="False"
                    ReadOnly="True" SortExpression="id" />
                <asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
                <asp:BoundField DataField="Lname" HeaderText="Lname" SortExpression="Lname" />
                <asp:TemplateField>
                <ItemTemplate>
                <asp:HyperLink ID="hp" Text="pass value" NavigateUrl="~/AA.aspx" runat="server"></asp:HyperLink>
                </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server"
            ConnectionString="<%$ ConnectionStrings:QConnectionString %>"
            SelectCommand="SELECT [id], [name], [Lname] FROM [registration]">
        </asp:SqlDataSource>
        <br />
        <br />
    </div>
    </form>
</body>


In page behind code is:
C#
public partial class Default7 : System.Web.UI.Page
{
    string ss;
    SqlConnection cn = new SqlConnection(@"Data Source=.\sqlexpress;Initial Catalog=Q;Integrated Security=True");
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        foreach(GridViewRow gr in GridView1.Rows)
        {
            HyperLink idd = (HyperLink)gr.FindControl("hp");
            if (idd)
            {
                ss = gr.Cells[2].Text; 
            }
            Session["dd"] = ss.ToString();
        }
    }
}

In another page coding is:

C#
public partial class AA : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Label1.Text = Convert.ToString(Session["dd"]);
    }
}


Can you help me to solve this problem.

Thanks in Advance.
Posted
Updated 7-Jul-11 18:40pm
v5

If you want to redirect from your hyperlink, you may want to append a querystring argument to the end of the href with the information you want to pass and then parse it out of there in the consuming page.
 
Share this answer
 
MIDL
string strLink1 = "Page.aspx?id=" +value + "& name=" +value + "";

          ((HyperLink)e.Row.Cells[i].Controls[1]).Attributes.Add("onclick", "open_win('" + strLink1 + "')");



Use This man..
 
Share this answer
 
Comments
Banajyotsna 8-Jul-11 2:42am    
Sir where i have to write this coding?can you give that coding briefly?
Hi,


You can do the same in diffrent diffrent ways.You can pass the data as query string or you can fire an event in the server side an daccept the text there and pass it to teh next page.

Regards,
shefeek
 
Share this answer
 
we can transfer data from one page to other by "server.transfer" and "response.redirect"
 
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