注册 登录
编程论坛 ASP.NET技术论坛

Gridview

馨馨 发布于 2008-04-07 21:33, 1319 次点击
想把Gridview中的一个从数据库中读出的字段加上超链接,使一点击它就可以跳转到其他的页面中。怎么设置呢
10 回复
#2
ilovetea2008-04-07 21:46
在代码中找到你想修改的列,比如"学号":

<asp:HyperLinkField DataTextField="学号" HeaderText="学号" DataNavigateUrlFields="学号" DataNavigateUrlFormatString="Default.aspx?id={0}" />
#3
hebingbing2008-04-07 21:51
你要是要在字段上要加上链接的话,那样你要用在建立列字段的时候选择templatefield,然后
 <ItemTemplate>   
  <asp:HyperLink   id="xxx"   runat="server" Text='<%# DataBinder.Eval(container.DataItem,"name") %>‘  NavigateUrl='<%#"showproc.aspx?id="+DataBinder.Eval(Container.DataItem,"productid")%>'>   
  </ItemTemplate>

[[it] 本帖最后由 hebingbing 于 2008-4-7 22:08 编辑 [/it]]
#4
馨馨2008-04-07 22:07
在哪选templatefield呢,在数据库中吗 怎么没有这个呢
#5
hebingbing2008-04-07 22:10
你选择列字段的时候是不是选择的是BoundField啊,就在你选择BoundField的那里选……
#6
馨馨2008-04-07 22:27
我用的是VS05啊 怎么找不到BoundField呢
#7
馨馨2008-04-07 22:33
找到了 谢谢
#8
馨馨2008-04-07 22:50
我加了代码,但是它报错了,你看看我的代码把,
  <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
                                    Width="581px" CellPadding="0" GridLines="None" Height="119px" SelectedIndex="0" AllowPaging="True" HorizontalAlign="Center">
                                    <Columns>
                                        <asp:BoundField DataField="nname" HeaderText="新闻标题" SortExpression="nname" />
                                        <asp:BoundField DataField="dates" HeaderText="发布日期" SortExpression="dates" />
                                        <asp:TemplateField>
                                        <ItemTemplate>   
                                          <asp:HyperLink   id="h1"   runat="server" Text="<%# DataBinder.Eval(container.DataItem,"name") %>"  NavigateUrl="<%#"gstz.aspx?id="+DataBinder.Eval(Container.DataItem,"productid")%>"/>   
                                                </ItemTemplate>
                                        </asp:TemplateField>
                                    </Columns>
                                    
                                    <FooterStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                                    <AlternatingRowStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                                    <EmptyDataRowStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                                    <RowStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                                    <EditRowStyle Font-Names="宋体" HorizontalAlign="Center" VerticalAlign="Middle" />
                                    <SelectedRowStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                                    <PagerStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                                    <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                                </asp:GridView>



错误    1    服务器标记的格式不正确。    C:\Inetpub\wwwroot\pp\login.aspx    200
#9
馨馨2008-04-07 23:29
脸上之后有出现这个问题了 你给的代码我加上了,也调好了,但是一运行就出下面的错,你给看看把 谢谢了
#10
jalonlovesja2008-04-08 17:22
<asp:HyperLinkField DataNavigateUrlFields="PrCompanyName,Prid" DataNavigateUrlFormatString="SelectProducts.aspx?PrCompanyName={0}"
                                HeaderText="供应商" DataTextField="PrCompanyName" />
是这段代码了。
#11
mycroo2008-04-11 14:20
我也想问这样的问题啊!我的是新闻发布系统,一旦选定了一个新闻标题它会转向另一个页面,而另一个页面会根据上个页面传过来的值从数据库中读取新闻的详细信息,如何实现,用的是gridview控件
1