DataNavigateUrlFormatString的使用方法
例如:
代码如下:
<asp:GridView ID="NewsGrid" runat="server" AllowPaging="True" AutoGenerateColumns="False"
CellPadding="4" ForeColor="#333333" GridLines="None" PageSize="4" Width="100%" OnPageIndexChanging="NewsGrid_PageIndexChanging" OnSelectedIndexChanged="NewsGrid_SelectedIndexChanged">
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:BoundField DataField="NewsType" HeaderText="新闻分类" />
<asp:HyperLinkField DataNavigateUrlFields="NewsID,TitleStr" DataNavigateUrlFormatString="ViewNews.aspx?NewsID={0}&TitleStr={1}"
DataTextField="TitleStr" HeaderText="新闻主题" />
<asp:BoundField DataField="VisitInt" HeaderText="点击次数" />
<asp:BoundField DataField="NameStr" HeaderText="发布人" />
<asp:BoundField DataField="DateTimeTxt" HeaderText="发布日期" />
</Columns>
<RowStyle BackColor="#FFFBD6" Font-Size="Smaller" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
红色部分:{0}{1}实际上就是占位符,对应的是DataNavigateUrlFields="NewsID,TitleStr"中的字段。和Console.Write("{0}",name);
点击,发现地址为:http://localhost:6776/NewsWeb/ViewNews.aspx?NewsID=18&TitleStr=rrrr(本机测试结果)