我已经创建了一个datagrid并将它链接到我的数据库中的一个表中,然后我想添加一个hyperlink,它应该从table绑定到一个column
<asp:DataGrid ID="DataGrid1" runat="server" DataSourceID="SqlDataSource1">
</asp:DataGrid>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:holidaysConnectionString %>"
SelectCommand="SELECT [Name], [External_Link] FROM [Person]">
</asp:SqlDataSource>
<asp:HyperLink ID="hyperlink" runat="server" NavigateUrl='http://www.google.com/<%# Bind("External_Link")%>' Target="_blank">Visit Google</asp:HyperLink>这不管用,有人能告诉我做错了什么吗?
我的table、Name和External_Hyperlink中有2列,每一行( external_hyerplink列内)都包含url的扩展名,因此根据单击的行,我将得到www.google.com/extension1__或www.google.com/extension2 etc.
但别以为我的方向是对的。请给我一些解决问题的办法。
发布于 2013-01-10 19:35:54
请将此作为一个示例:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="ProblemID" />
<asp:HyperLinkField DataNavigateUrlFields="ProblemID" DataNavigateUrlFormatString="SmallWindow.aspx?id={0}"
DataTextField="Click here" NavigateUrl="SmallWindow.aspx" />
<asp:BoundField DataField="Solution" />
</Columns>
</asp:GridView>或
//This event should fire on Row Data Bound
protected void yourGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
HyperLink hlControl = new HyperLink();
hlControl.Text = e.Row.Cells[2].Text; //Take back the text (let say you want it in cell of index 2)
hlControl.NavigateUrl = "http://www.stackoverflow.com";
e.Row.Cells[2].Controls.Add(hlControl);//index 2 for the example编辑
试着做这样的事情:
<asp:HyperLink ID="HyperLink2" runat=server NavigateUrl='<%#Eval("Company_ID", "CompanyProfile.aspx?ID={0}")%>'><%#Eval("Name")%></asp:HyperLink>https://stackoverflow.com/questions/14265679
复制相似问题