ASP.NET+GridView实现行链接

40 篇文章 0 订阅
28 篇文章 0 订阅
后台代码:

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("style", "cursor:pointer;");           // 将光标设为手形


            // 当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色
            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='pink',this.style.fontWeight='';");
            // 当鼠标离开的时候 将背景颜色还原的以前的颜色
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");


            e.Row.Attributes.Add("OnClick", "ClickEvent('" + e.Row.Cells[1].Text + "')");
        }
    }

前台代码:
    <script type="text/javascript">
    function ClickEvent(d) {
      //window.alert("事件类型: OnClick  作用对象: " + d);
      window.open("ShowMsg.aspx?Title=" + d); // 打开链接
    }
    </script>


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ASP.NET 中,可以通过使用全文检索功能实现 `Ctrl+F` 的页面搜索功能。 首先,需要在 Visual Studio 中安装 SQL Server Full-Text Search 组件,然后在数据库中创建全文索引。具体操作步骤可以参考以下链接: - [如何在 SQL Server 中创建全文索引](https://docs.microsoft.com/zh-cn/sql/relational-databases/search/create-and-manage-full-text-indexes?view=sql-server-ver15) 创建好全文索引后,我们可以在 ASP.NET 中使用 `SqlDataSource` 控件来查询数据。在查询条件中,我们可以使用 `CONTAINS` 函数来进全文检索。 下面是一个简单的示例代码: ```aspx <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:myConnectionString %>" SelectCommand="SELECT * FROM myTable WHERE CONTAINS(*, @searchText)"> <SelectParameters> <asp:Parameter Name="searchText" Type="String" /> </SelectParameters> </asp:SqlDataSource> <asp:TextBox ID="searchBox" runat="server"></asp:TextBox> <asp:Button ID="searchButton" runat="server" Text="搜索" OnClick="searchButton_Click" /> <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1"></asp:GridView> ``` 在上述代码中,我们使用了 `SqlDataSource` 控件来查询数据,其中的 `SelectCommand` 属性使用了 `CONTAINS` 函数进全文检索。在页面中,我们使用一个文本框和一个按钮来让用户输入要搜索的内容,并在按钮点击事件中设置 `SqlDataSource` 的 `SelectParameters` 参数,然后将查询结果绑定到 `GridView` 控件上。 下面是按钮点击事件的示例代码: ```csharp protected void searchButton_Click(object sender, EventArgs e) { SqlDataSource1.SelectParameters["searchText"].DefaultValue = searchBox.Text; GridView1.DataBind(); } ``` 需要注意的是,全文检索功能需要占用一定的系统资源,并且在查询大量数据时可能会影响性能。因此,在实际应用中需要根据实际情况进权衡和优化。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值