本文介绍了如何使用gridview超链接完成此任务...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两页。网格视图页面和配置文件页面。
在第一页中,有一个数据绑定字段(id)和超链接(配置文件)。
如果我点击超链接,我可以在单独的网页上查看完整的员工详细信息(使用id作为会话)
Plz帮助我...
提前谢谢你
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
推荐答案
<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
_________________________________
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
_____________________________
Default2.aspx.cs
_____________________________
protected void Page_Load(object sender, EventArgs e)
{
string id=Request.QueryString["id"];//for query string
//string id1 = Session["id"].ToString();//for session
}
这篇关于如何使用gridview超链接完成此任务...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!