gpt4 book ai didi

c# - 如何在gridview中的每一行创建一个到asp.net中另一个操作的超链接?

转载 作者:行者123 更新时间:2023-11-29 12:29:07 25 4
gpt4 key购买 nike

我是asp.net的初学者。我认为这个问题对于专家来说很愚蠢。问题是我在 mysql 中有一个学生表。学生表有一个名为“batch”的列。当用户搜索批处理时,该批处理中的学生姓名将出现在 gridview 表中。

现在我想为每一列建立链接,以便如果用户单击表格的一行,则该学生的完整个人资料会显示在新页面中。

如何将行设置为超链接?

最佳答案

您应该在 GridView 标记之间添加 OnRowDataBound="GridView1_RowDataBound" ,如下所示;

  <asp:GridView AllowPaging="true" PageSize="20" CssClass="table table-striped table-bordered table-hover" ID="GridView1" runat="server"
OnPageIndexChanging="GridView1_PageIndexChanging" OnRowDataBound="GridView1_RowDataBound">
</asp:GridView>

添加这些代码并用您的 SQL 查询名称更改“ColumName”。

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string MyId = DataBinder.Eval(e.Row.DataItem, "ColumnName").ToString();
string Location = ResolveUrl("~/Your.aspx") + "?ColumName=" + MyId;
e.Row.Attributes["onClick"] = string.Format("javascript:window.location='{0}';", Location);
e.Row.Style["cursor"] = "pointer";
}
}

关于c# - 如何在gridview中的每一行创建一个到asp.net中另一个操作的超链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27865731/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com