首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将navigateURL绑定到数据集

将navigateURL绑定到数据集
EN

Stack Overflow用户
提问于 2013-01-10 19:23:18
回答 1查看 3.8K关注 0票数 0

我已经创建了一个datagrid并将它链接到我的数据库中的一个表中,然后我想添加一个hyperlink,它应该从table绑定到一个column

代码语言:javascript
复制
 <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>

这不管用,有人能告诉我做错了什么吗?

我的tableNameExternal_Hyperlink中有2列,每一行( external_hyerplink列内)都包含url的扩展名,因此根据单击的行,我将得到www.google.com/extension1__或www.google.com/extension2 etc.

但别以为我的方向是对的。请给我一些解决问题的办法。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-01-10 19:35:54

请将此作为一个示例:

代码语言:javascript
复制
<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>

代码语言:javascript
复制
//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

编辑

试着做这样的事情:

代码语言:javascript
复制
<asp:HyperLink ID="HyperLink2" runat=server NavigateUrl='<%#Eval("Company_ID", "CompanyProfile.aspx?ID={0}")%>'><%#Eval("Name")%></asp:HyperLink>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14265679

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档