在网上搜索了两天,还是没搞明白.只好再来求教大家!
我的GRIDVIEW是自动绑定的,就是不是我一列列地绑的...
然后现在显示会有"序号","商品名称","厂家"等信息.就是这样: 序号 商品 厂家
1 A 甲
2 B 丙然后我希望能把序号这一列做成超链接,我点击某一条记录的序号,就会出来对应的更加详细的信息....请高手指点一下到底要怎么把某一列设为超链接!!!!
我的GRIDVIEW是自动绑定的,就是不是我一列列地绑的...
然后现在显示会有"序号","商品名称","厂家"等信息.就是这样: 序号 商品 厂家
1 A 甲
2 B 丙然后我希望能把序号这一列做成超链接,我点击某一条记录的序号,就会出来对应的更加详细的信息....请高手指点一下到底要怎么把某一列设为超链接!!!!
增加一列
<asp:HyperLinkField DataNavigateUrlFields="stuSchoolID" DataNavigateUrlFormatString="stuInfo.aspx?stuID={0}" <
DataTextField="超链接数据库字段" HeaderText="标题" Target="_blank" >
<ItemStyle Font-Bold="False" Wrap="False" Font-Names="Verdana" />
<HeaderStyle HorizontalAlign="Center" Wrap="False" />
</asp:HyperLinkField>DataNavigateUrlFormatString 为你要跳转的页面
DataTextField="序号(或者厂家都可以)" HeaderText="标题" Target="_blank" >
<ItemStyle Font-Bold="False" Wrap="False" Font-Names="Verdana" />
<HeaderStyle HorizontalAlign="Center" Wrap="False" />
</asp:HyperLinkField>
<a href="转向的页面">内容</a>
</ItemTemplate>
<ItemTemplate>
<a href="转向的页面">内容 </a>
</ItemTemplate>
参考代码:
<asp:GridView ID="GridView1" runat="server" Width="680px"
AutoGenerateColumns="False" DataKeyNames="KHID"
>
<Columns>
<asp:HyperLinkField DataNavigateUrlFields="KHID"
DataNavigateUrlFormatString="Show_CustomerInfo.aspx?KHID={0}"
DataTextField="KHID" HeaderText="用户ID" Target="_blank" />
<asp:BoundField DataField="KHDM" HeaderText="用户代码" />
<asp:BoundField DataField="MC" HeaderText="用户名称" />
</Columns>
</asp:GridView>
Style="font-size: 13px" CellPadding="4" ForeColor="#333333"
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<EditRowStyle BackColor="#999999" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:TemplateField HeaderText="序号">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" Style=" position:relative"
Text='<%# Eval("你的数据库中“序号”的字段") %>'
NavigateUrl='<%# Eval("随便写,比如NOTICEID","~/你要传的页面.aspx?NOTICEID={0}") %>'></asp:HyperLink>
</ItemTemplate>
<ItemStyle Width="50px" />
<HeaderStyle Width="1%" Wrap="false" />
</asp:TemplateField>
<asp:BoundField DataField="你的数据库中“商品”的字段" HeaderText="商品" >
<ItemStyle Width="100px" />
</asp:BoundField>
<asp:BoundField DataField="你的数据库中“厂家”的字段" HeaderText="厂家" >
<ItemStyle Width="150px" />
</asp:BoundField>
</Columns>
</asp:GridView>
我懂你意思了:
有办法,当绑定结束后,修改原序号列的内容,改为链接列 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[0].Text = "<a href='info.aspx?ID=" + e.Row.Cells[0].Text + "' target='_blank'>" + e.Row.Cells[0].Text + "</a>";
}
}
DataTextField="超链接数据库字段" HeaderText="标题" Target="_blank" >
<ItemStyle Font-Bold="False" Wrap="False" Font-Names="Verdana" />
<HeaderStyle HorizontalAlign="Center" Wrap="False" />
</asp:HyperLinkField>