通过单击gridview的herperlink,我将如何将一个值从一页传递到另一页 [英] By clicking herperlink of gridview how i will pass one value from one page to another

查看:59
本文介绍了通过单击gridview的herperlink,我将如何将一个值从一页传递到另一页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬的先生,

我已经在gridview内获取了超链接.如何通过单击gridview内的超链接将一个值从一个页面传递到另一页面.设计页面中的编码是

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

<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:

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:

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.

推荐答案

ConnectionStrings:QConnectionString %> " span> =" 从[注册]中选择[id],[name],[Lname]" < /asp:SqlDataSource > < br > < br > < /div > < /form > < /body >
ConnectionStrings:QConnectionString %>" SelectCommand="SELECT [id], [name], [Lname] FROM [registration]"> </asp:SqlDataSource> <br /> <br /> </div> </form> </body>



在页面后面的代码是:



In page behind code is:

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:

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.


如果您想从超链接进行重定向,则可能需要在href的末尾附加一个要传递的信息的querystring参数,然后将其解析出来.
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.


string strLink1 = "Page.aspx?id=" +value + "& name=" +value + "";

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




使用这个人.




Use This man..


这篇关于通过单击gridview的herperlink,我将如何将一个值从一页传递到另一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆