我想用HyperLink绑定数据库中的ID,name,ID作为参数提交到另一个页面!!
这是我写的代码:
<TABLE cellSpacing="0" cellPadding="0" width="100%" border="0">
<TR>
<TD width="10%" height="24">
<DIV align="center"><IMG height="13" src="../Material/images/logo07.gif" width="13"></DIV>
</TD>
<TD width="90%" height="24"><STRONG>
<asp:HyperLink id=Hyperlink2 NavigateUrl='<%# "Detail.aspx?Code="+DataBinder.Eval(Container.DataItem, "N_ID")%>' text='<%# DataBinder.Eval(Container.DataItem, "N_title") %>' Runat="server">
</asp:HyperLink></STRONG></TD>
</TR>
</TABLE>这是html中的代码。
请问.cs中怎么样绑定数据库。

解决方案 »

  1.   

    http://chs.gotdotnet.com/quickstart/util/srcview.aspx?path=/quickstart/aspplus/samples/webforms/customize/datalist4.src&file=CS\DataList4.aspx&font=3
      

  2.   

    除了这些,还有其它的代码吗,我想绑定数据库。谢谢WTaoboy(SnowMans)
      

  3.   

    http://www.cnblogs.com/lovecherry/archive/2005/03/25/125510.html参考
      

  4.   

    请问hackate(兰花开香入梦境,独思佳人亦飘然!!) 你自己有写过的代码没有关于hplink。谢谢
      

  5.   

    If you want to display the detail of the particular customer if the new page (custdetails.aspx), then use the hyperlink ; if you want to display it in the same page, then use the LinkButton
     
    Hyperlink
    <asp:HyperlinkColumn
            HeaderText="Customer ID"
            DataTextField="cust_id"
            DataNavigateUrlField="cust_id"
            DataNavigateUrlFormatString="custdetails.aspx?custid={0}"
            Target="_blank"/>
     
    In the custdetails.aspx page, obtain the custid query string and do your selecting query appropriately.
     
    LinkButton
    <asp:TemplateColumn>
           <ItemTemplate>
                 <asp:linkbutton id="lbtnCustID" Text='<%# DataBinder.Eval(Container.DataItem,"cust_id") %>' .............
          </ItemTemplate>
    </asp:TemplateColumn>
     
    Use the FindControl() to find the linkbutton, then obtain its Text property to get the customer ID. 
      

  6.   

    再次请问大家,自己写过hplink的代码没有,能否给小弟一个。谢谢大家
      

  7.   

    http://www.c-sharpcorner.com/Code/2003/June/DataGridHyperLinkColumn.asp
      

  8.   

    请问renyu732(在学.net中...).cs中的代码该怎么写,谢谢,我就这个不是很会,还有我必须用DataGrid或DataList才能用hplink 吗
      

  9.   

    <asp:TemplateColumn>
    <ItemTemplate>
    <asp:HyperLink ID="NewsTitle1" Text='<%# Left(CType(DataBinder.Eval(Container.DataItem,"Title"),String),20)+"..."%>' NavigateUrl='<%# "newsDetail.aspx?id="+DataBinder.Eval(Container.DataItem,"id").ToString() %>' Target=_blank Runat=server />
    </ItemTemplate>
    </asp:TemplateColumn>刚才写的.
      

  10.   

    你问怎么拌定数据库
    <asp:HyperLink id=Hyperlink2 NavigateUrl='<%# "Detail.aspx?Code="+DataBinder.Eval(Container.DataItem, "N_ID")%>' text='<%# DataBinder.Eval(Container.DataItem, "N_title") %>' Runat="server">
    这里面N_ID就是字段。N_title也是字段那么这个拌定数据库就是跟普通拌定datagrid啊。如果你这个是应用在datagrid上。你拌定datagrid
    只要你这个hyperlink在datagrid里,他就会自动拌定了啊。
      

  11.   

    当然不是,刚才只是将HyperLink嵌入DataGrid等了.你可以想怎么用就怎么用了.至于你说的在.cs中应该怎么写,请再说清楚一些.
    比如,你是想将数据绑定到HyperLink呢?还是想在.cs中动态生成HyperLink?
      

  12.   

    如果不用datagrid可以使用hplink吗??、
      

  13.   

    绑定数据库上的数据的话:
    <asp:HyperlinkColumn
            HeaderText="Customer ID"
            DataTextField="cust_id"
            DataNavigateUrlField="cust_id"
            DataNavigateUrlFormatString="custdetails.aspx?custid={0}"
            Target="_blank"/>
    其中的Customer ID,cust_id等都是从数据库表的字段。
    .vb如:
    Sub ShowStars()
            Dim comm As New SqlDataAdapter("Select * from Stars", conn)
            Dim ds As New DataSet
            comm.Fill(ds, "Stars")
            HyperLink1.DataSource = ds.Tables("Stars").DefaultView
            HyperLink1.DataBind()
    End Sub.cs
    void ShowStars() 

     SqlDataAdapter comm = new SqlDataAdapter("Select * from Stars", conn); 
     DataSet ds = new DataSet(); 
     comm.Fill(ds, "Stars"); 
     Hyperlink1.DataSource = ds.Tables("Stars").DefaultView; 
     HyperLink1.DataBind(); 
    }
      

  14.   

    使用 DataGrid 控件中的 HyperLinkColumn 列类型为 DataGrid 中的每行创建超级链接。设置 Text 属性以指定超级链接的标题文本。若要指定当单击超级链接时链接到的 URL,请设置 NavigateUrl 属性。
    注意   如果设置了 Text 和 NavigateUrl 属性,则列中的所有超级链接将共享同一标题和 URL。
    还可以将 HyperLinkColumn 中的超级链接的文本标题和 URL 绑定到数据源中的字段,而不是设置 Text 和 NavigateUrl 属性。这使您得以为列中的每个超级链接显示不同的标题和指定不同的 URL。
    使用 DataTextField 属性指定数据源中的字段以绑定到列中超级链接的文本标题。
    注意   不能同时设置 DataTextField 和 Text 属性。如果同时设置了这两个属性,则 DataTextField 属性优先。
    通过设置 DataNavigateUrlField 属性指定要绑定到超级链接的 URL 的字段。
    注意   不能同时设置 DataNavigateUrlField 和 NavigateUrl 属性。如果同时设置了这两个属性,则 DataNavigateUrlField 属性优先。
    Target 属性使您得以指定窗口或框架以显示单击超级链接时链接到的 Web 页内容。
    当使用数据绑定时,可以通过设置 DataTextFormatString 和 DataNavigateUrlFormatString 属性分别格式化超级链接的文本标题和 URL。
    警告   在文本显示在 HyperLinkColumn 中之前,它是没有经过 HTML 编码的。这使您得以在文本的 HTML 标记内嵌入脚本。若该列的值来自用户输入,请一定验证这些值以防出现安全隐患。
    示例
    [Visual Basic, C#] 下面的示例说明如何创建一个链接到单独一页的 HyperLinkColumn。
    [Visual Basic] 
    <%@ Page Language="VB" AutoEventWireup="True" %>
    <%@ Import Namespace="System.Data" %><html><head>   <script runat="server">      Function CreateDataSource() As ICollection 
          
             Dim dt As DataTable = New DataTable()
             Dim dr As DataRow
             Dim i As Integer         dt.Columns.Add(New DataColumn("IntegerValue", GetType(Int32)))
             dt.Columns.Add(New DataColumn("PriceValue", GetType(Double)))
           
             For i = 0 to 2 
             
                dr = dt.NewRow()            dr(0) = i
                dr(1) = CDbl(i) * 1.23            dt.Rows.Add(dr)         Next i         Dim dv As DataView = New DataView(dt)
             Return dv      End Function      Sub Page_Load(sender As Object, e As EventArgs) 
        
             MyDataGrid.DataSource = CreateDataSource()
             MyDataGrid.DataBind()      End Sub   </script></head><body>   <form runat="server">      <h3>HyperLinkColumn Example<h3>      <asp:DataGrid id="MyDataGrid" 
               BorderColor="black"
               BorderWidth="1"
               GridLines="Both"
               AutoGenerateColumns="false"
               runat="server">         <HeaderStyle BackColor="#aaaadd"/>         <Columns>            <asp:HyperLinkColumn
                     HeaderText="Select an Item"
                     DataNavigateUrlField="IntegerValue"
                     DataNavigateUrlFormatString="detailspage.aspx?id={0}"
                     DataTextField="PriceValue"
                     DataTextFormatString="{0:c}"
                     Target="_blank"/>
               
             </Columns>      </asp:DataGrid>   </form></body>
    </html>
    [C#] 
    <%@ Page Language="C#" AutoEventWireup="True" %>
    <%@ Import Namespace="System.Data" %><html><head>   <script runat="server">      ICollection CreateDataSource() 
          {
             DataTable dt = new DataTable();
             DataRow dr;         dt.Columns.Add(new DataColumn("IntegerValue", typeof(Int32)));
             dt.Columns.Add(new DataColumn("PriceValue", typeof(Double)));
           
             for (int i = 0; i < 3; i++) 
             {
                dr = dt.NewRow();            dr[0] = i;
                dr[1] = (Double)i * 1.23;            dt.Rows.Add(dr);
             }         DataView dv = new DataView(dt);
             return dv;
          }      void Page_Load(Object sender, EventArgs e) 
          {
             MyDataGrid.DataSource = CreateDataSource();
             MyDataGrid.DataBind();
          }   </script></head><body>   <form runat="server">      <h3>HyperLinkColumn Example<h3>      <asp:DataGrid id="MyDataGrid" 
               BorderColor="black"
               BorderWidth="1"
               GridLines="Both"
               AutoGenerateColumns="false"
               runat="server">         <HeaderStyle BackColor="#aaaadd"/>         <Columns>            <asp:HyperLinkColumn
                     HeaderText="Select an Item"
                     DataNavigateUrlField="IntegerValue"
                     DataNavigateUrlFormatString="detailspage.aspx?id={0}"
                     DataTextField="PriceValue"
                     DataTextFormatString="{0:c}"
                     Target="_blank"/>
               
             </Columns>      </asp:DataGrid>   </form></body>
    </html>
    [Visual Basic, C#] 下面的相应示例显示在上一示例中选择的项。
    [Visual Basic] 
    <%@ Page Language="VB" AutoEventWireup="True" %>
    <html>
    <head>
     
       <script runat="server">
     
          Sub Page_Load(sender As Object, e As EventArgs) 
          
             Label1.Text = "You selected item: " & Request.QueryString("id")
          
          End Sub
     
       </script>
     
    </head>
    <body>
     
       <h3>Details page for DataGrid</h3>
     
       <asp:Label id="Label1"
            runat="server"/>
     
    </body>
    </html>
    [C#] 
    <%@ Page Language="C#" AutoEventWireup="True" %>
    <html>
    <head>
     
       <script runat="server">
     
          void Page_Load(Object sender, EventArgs e) 
          {
             Label1.Text = "You selected item: " + Request.QueryString["id"];
          }
     
       </script>
     
    </head>
    <body>
     
       <h3>Details page for DataGrid</h3>
     
       <asp:Label id="Label1"
            runat="server"/>
     
    </body>
    </html>
      

  15.   

    请问renyu732(在学.net中...) HyperLink1.DataSource = ds.Tables("Stars").DefaultView
            HyperLink1.DataBind()里;
    HyperLink1好像没有DataSource这个属性,你是怎么得到,谢谢
      

  16.   

    不好意思,楼主.我写错了.是DataGrid1.DataSource...
    DataGrid1.DataBind()
    也就是说HyperLinkColumn作为DataGrid中的一个属性出现的..
    将数据绑定到DataGrid后,就可以将字段绑定到HyperLinkColumn的
    HeaderText="Customer ID"
    DataTextField="cust_id"
    DataNavigateUrlField="cust_id"
    了.
    不知道说明白没有.
      

  17.   

    另外强调是HyperLinkColumn而非HyperLink
      

  18.   

    ~~~~
    this.hlkAPP.Text = sFileName;
    this.hlkAPP.NavigateUrl = "../resource/upload/"+sFileName;
    this.hlkAPP.Target = "_blank";
    ~~~~~~
    在后台用代码操纵,当然hlkAPP是指hyperLink 对象了。
      

  19.   

    http://www.microsoft.com/china/MSDN/library/WebServices/ASP.NET/CreatingCustomColumnsfortheASP.NETDatagrid.mspx
      

  20.   

    http://www.microsoft.com/china/MSDN/library/WebServices/ASP.NET/CreatingaPageableSortableDataGrid.mspx
      

  21.   

    Hyperlink2.NavigateUrl=""
    Hyperlink2.Text=""
    这样的形式来绑定