当前位置:编程学习 > C#/ASP.NET >>

GridView绑定链接问题

GridView绑定数据库,其中有一列是网站地址,像“www.baidu.com"、“www.hao123,com"之类,点击后怎么在新窗口中打开? --------------------编程问答-------------------- --------------------编程问答-------------------- 这个我知道,是打开新页面。但是打开之后是在站内打开,就是像这样“http://localhost:3919/Web/Admin/%3C%#%20Bind%28%22Room3D%22%29%20%%3E&” ,而我想的是“http://www.baidu.com"这样的,怎么跳出站内呢? --------------------编程问答--------------------
引用 2 楼 SuiShiGuang 的回复:
这个我知道,是打开新页面。但是打开之后是在站内打开,就是像这样“http://localhost:3919/Web/Admin/%3C%#%20Bind%28%22Room3D%22%29%20%%3E&” ,而我想的是“http://www.baidu.com"这样的,怎么跳出站内呢?

你的意思是直接打开浏览器打开那个页面?貌似这样写是不行的,具体怎么弄我也不太清楚 --------------------编程问答-------------------- http://localhost:3919/Web/Admin/%3C%#%20Bind%28%22Room3D%22%29%20%%3E&

应该是你的代码写错了。

贴你的代码 --------------------编程问答-------------------- 话说net_lover的方法不对吗?
不就是加一个模板列,然后target="_blank",用eval绑定数据,点击不就可以吗? --------------------编程问答-------------------- <asp:GridView ID="GridViewRoom3D" runat="server" AutoGenerateColumns="False"   Width="100%"     
    
  style="margin-bottom: 0px" CellPadding="4" ForeColor="#333333" GridLines="None" 
                    >
                    <AlternatingRowStyle BackColor="White" />
                    <Columns>
                        <asp:TemplateField HeaderText="选择" >
                            <ItemTemplate>
                                <asp:CheckBox ID="CheckBox1" runat="server" />
                            </ItemTemplate>
                        </asp:TemplateField  >
                        <asp:TemplateField  HeaderText="ID"  Visible="false" >
                            <ItemTemplate>
                                <asp:Label ID="LabID" runat="server" Text='<%# Bind("ID") %>' ></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="房间编号">
                            <ItemTemplate>
                                <asp:Label ID="lblRoomId" runat="server" Text='<%# Bind("RoomId") %>' ></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="房间名称">
                            <ItemTemplate>
                                <asp:Label ID="lblRname" runat="server" Text='<%# Bind("Rname") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="所在楼栋">
                            <ItemTemplate>
                                <asp:Label ID="lblBuildId" runat="server" Text='<%# Bind("BuildId") %>' Visible="false"></asp:Label>
                                <asp:Label ID="lblBuildName" runat="server" ></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="管理" ShowHeader="False">
                            <ItemTemplate>
                                <asp:LinkButton ID="LinkButtonDel" runat="server"  ForeColor="Red"
                           Text="删除" onclick="LinkButtonDel_Click" ></asp:LinkButton>
                                    
                                <asp:LinkButton ID="LinkButtonEdit" runat="server" 
                             Text="编辑" onclick="LinkButtonEdit_Click"></asp:LinkButton>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:HyperLinkField DataTextField="room3d" Target="_blank" NavigateUrl='<%# Bind("Room3D") %>&' 
                         />
                        <asp:TemplateField>
                            <ItemTemplate>
                                <asp:LinkButton ID="LinkButtonHttp" runat="server" 
                                    onclick="LinkButtonHttp_Click">LinkButton</asp:LinkButton>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                    <EditRowStyle BackColor="#7C6F57" />
                    <EmptyDataTemplate>
               现在还未添加数据
                    </EmptyDataTemplate>
                    <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                    <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                    <PagerSettings FirstPageText="首页" LastPageText="末页" NextPageText="下一页" 
               PreviousPageText="上一页"  />
                    <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center"  />
                    <RowStyle BackColor="#E3EAEB" HorizontalAlign="Center" />
                    <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
                    <SortedAscendingCellStyle BackColor="#F8FAFA" />
                    <SortedAscendingHeaderStyle BackColor="#246B61" />
                    <SortedDescendingCellStyle BackColor="#D4DFE1" />
                    <SortedDescendingHeaderStyle BackColor="#15524A" />
                </asp:GridView> --------------------编程问答-------------------- 红色部分和下面那个“ <asp:LinkButton ID="LinkButtonHttp" runat="server" 
                                    onclick="LinkButtonHttp_Click">LinkButton</asp:LinkButton>” ,应该用哪个?

     --------------------编程问答-------------------- 你红字标注部分第一行最后那边多了个&,去掉以后会提示缺少ID
自己GOOGLE下原因
我给你提供一种我自己用的
                                  <asp:TemplateField HeaderText="网址" HeaderStyle-Width="300px" ItemStyle-HorizontalAlign="Left">
                                    <ItemTemplate >
                                         <asp:HyperLink runat="server" Target="_blank" ID="hlPath" Text='<%# Bind( "fchrWeb") %>' NavigateUrl='<%# Bind( "fchrWeb") %>'></asp:HyperLink>
                                       </ItemTemplate>
                                    <ItemStyle />
                                </asp:TemplateField>
--------------------编程问答-------------------- 打开链接后是这样的?http://localhost:3919/Web/Admin/www.baidu.com --------------------编程问答-------------------- GRIDVIEW加个临时列 --------------------编程问答--------------------
引用 9 楼 SuiShiGuang 的回复:
打开链接后是这样的?http://localhost:3919/Web/Admin/www.baidu.com


前面给你说了,你数据库存储的必须是http://开头的,不能是www开头,www开头不是一个有效的url
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,