我想动态地在网格视图中添加一个链接按钮,该按钮应该保留参数,当用户点击按钮时,它必须转到我映射的相应页面
例如:如果按钮文字是“查看更多”,当用户点击按钮时,按钮将传递“id”值,它将移至Details.aspx?id=10
,在该页面上,它将通过检索来显示数据使用该id值的数据库。
我知道如何从数据库中检索数据。但我不知道带参数的热添加链接按钮。
这是我的代码
protected void Page_Load(object sender, EventArgs e)
{
// data load to grid view
loadDataTable();
}
private void loadDataTable()
{
DataSet ds = new DataSet();
DataTable dt;
DataRow dr;
DataColumn date;
DataColumn designation;
DataColumn experience;
DataColumn location;
DataColumn nationality;
DataColumn details;
dt = new DataTable();
date = new DataColumn("Date");
designation = new DataColumn("Designation");
experience = new DataColumn("Experience");
location = new DataColumn("Location");
nationality = new DataColumn("Nationality");
details = new DataColumn("Details");
dt.Columns.Add(date);
dt.Columns.Add(designation);
dt.Columns.Add(experience);
dt.Columns.Add(location);
dt.Columns.Add(nationality);
dt.Columns.Add(details);
dr = dt.NewRow();
dr["Date"] = "10/2/2016";
dr["Designation"] = "Asp.net";
dr["Experience"] = "5";
dr["Location"] = "Jeddah";
dr["Nationality"] = "Indian";
dr["Detais"] = ""; // ADD LINK BUTTON
dt.Rows.Add(dr);
ds.Tables.Add(dt);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
asp.net代码
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-12">
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
</div>
</div>
我想在Details标题中添加链接按钮。
请帮帮我。我是gridview和asp.net的新手
答案 0 :(得分:2)
如何添加锚点?
dr["Detais"] = "<a href='Details.aspx?id="+ dr["id"].ToString() + "' target='_blank'>View Details</a>";
我不确定id字段,但这可行
修改强>
将“详细信息”列更改为Literal
列,其内容如下:
<asp:TemplateField headertext="Details">
<ItemTemplate>
<asp:Literal id="Literal1" runat="server" text='<%# Eval ("Details") %>'></asp:Literal>
</ItemTemplate>
</asp:TemplateField>