Linq Datagrid源链接每一行

时间:2010-04-19 01:41:46

标签: c# asp.net linq datagridview

好的,我甚至不知道从哪里开始我会继续这个问题:Linq-to-SQL statement issue

我搜索表中的多个列并在数据网格中返回我的值, 我已经完成了网格上的基本格式化,但我无法破译我将如何进行 让每一行链接到另一个页面?

using (TiamoDataContext context = new TiamoDataContext())
    {
        var search = 
             from p in context.UserProfile1s
             where p.DanceType == UserSearchString ||
                   p.Username == UserSearchString ||
                   p.Occupation == UserSearchString ||
                   p.LookingFor == UserSearchString ||
                   p.Location == UserSearchString ||
                   p.LastName == UserSearchString ||
                   p.Gender == UserSearchString ||
                   p.FirstName == UserSearchString ||
                   p.DanceType == UserSearchString ||
                   p.DanceSong == UserSearchString ||
                   p.DanceLevel == UserSearchString ||
                   p.DanceIcon == UserSearchString ||
                   p.BodyBuild == UserSearchString ||
                   p.Age.ToString() == UserSearchString ||
                   p.AboutMe == UserSearchString
             select new
             {
                 Username = p.Username,
                 Firstname = p.FirstName,
                 Lastname = p.LastName,
                 Location = p.Location,
                 DanceType = p.DanceType
             };

        UserSearchGrid.DataSource = search;
        UserSearchGrid.DataBind();
    }

<asp:GridView ID="UserSearchGrid" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" Height="93px" Width="702px">
    <RowStyle BackColor="#EFF3FB" />
    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <EditRowStyle BackColor="#2461BF" />
    <AlternatingRowStyle BackColor="White" />
</asp:GridView>

谢谢,我知道你们今天帮我装了很多,我只是太享受了它的功能......

1 个答案:

答案 0 :(得分:0)

您可以使用hyperlinkField从网格中设置AutogenerateColumns属性并将其中一列设置为hyperlinkField这里是一个示例

<asp:gridview id="OrdersGridView" 
    datasourceid="OrdersSqlDataSource" 
    autogeneratecolumns="false"
    runat="server">

    <columns>

      <asp:boundfield datafield="OrderID" 
        headertext="OrderID"/>
      <asp:boundfield datafield="CustomerID" 
        headertext="Customer ID"/>
      <asp:boundfield datafield="OrderDate" 
        headertext="Order Date"
        dataformatstring="{0:d}" />
      <asp:hyperlinkfield text="Details..."
        navigateurl="~\details.aspx"            
        headertext="Order Details"
        target="_blank" />

    </columns>

  </asp:gridview>