日期:2014-05-18  浏览次数:20502 次

同一页面内的不同内容加载
网站的一个基本功能,即在一个页面内加载不同的内容,如某一页的
URL:****.aspx?PostID={0}
如.net   2.0   GridView中的HyperLinkField就有
DataNavigateUrlFormatString= "ShowNews.aspx?PostID={0} "的属性
页面内容的加载是怎样实现的,能不能给举个例子?



------解决方案--------------------

if
page A DataNavigateUrlFormatString= "ShowNews.aspx?id=1 "
page B get 内容 where id = 1

if
page A DataNavigateUrlFormatString= "ShowNews.aspx?id=2 "
page B get 内容 where id = 2
------解决方案--------------------
<asp:HyperLinkField DataTextField= "AgentName " HeaderText= "代理名称 " DataNavigateUrlFields= "Agentid " DataNavigateUrlFormatString= "song.aspx?id={0} " />

可以看出DataNavigateUrlFields是超链接可能会使用到的数据字段的字段名称,一般他会配合
DataNavigateUrlFormatString或者NavigateUrl这个来使用
如果DataNavigateUrlFields中有多个字段,在需要第一个字段时使用{0}, 第二个字段使用{1},以此类推.
------解决方案--------------------
<asp:GridView ID= "GridView1 " runat= "server " AutoGenerateColumns= "False " CellPadding= "4 "
DataKeyNames= "VoteId " DataSourceID= "sdsVote " ForeColor= "#333333 " GridLines= "None " Width= "778px " AllowPaging= "True " PageSize= "20 ">
<FooterStyle BackColor= "#507CD1 " Font-Bold= "True " ForeColor= "White " />
<Columns>
<asp:TemplateField HeaderText= "投票者ID ">
<ItemTemplate>
<a href= 'voteResult.aspx?VoteId= <%# DataBinder.Eval(Container.DataItem, "VoteId ") %> ' target= "_blank "> <%# DataBinder.Eval(Container.DataItem, "VoteId ") %> </a>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField= "UserInfo " HeaderText= "投票者信息 " SortExpression= "UserInfo " />
</Columns>
<RowStyle BackColor= "#EFF3FB " />
<EditRowStyle BackColor= "#2461BF " />
<SelectedRowStyle BackColor= "#D1DDF1 " Font-Bold= "True " ForeColor= "#333333 " />
<PagerStyle BackColor= "CornflowerBlue " ForeColor= "White " HorizontalAlign= "Left " Font-Size= "12px " />
<HeaderStyle BackColor= "#507CD1 " Font-Bold= "True " ForeColor= "White " />
<AlternatingRowStyle BackColor= "White " />
</asp:GridView>
<asp:SqlDataSource ID= "sdsVote " runat= "server " ConnectionString= " <%$ ConnectionStrings:fbcon %> "
SelectCommand= "SELECT [VoteId], [Need], [Channel], [ChannelOther], [Look], [Attention], [AttentionOther], [Accept], [Know], [KnowOther], [UserInfo] FROM [UserVote] ORDER BY [VoteId] Desc ">
</asp:SqlDataSource>
------解决方案--------------------
<asp:HyperLinkField DataTextField= "news_id " HeaderText= "ID "
DataNavigateUrlFields = "news_id,等 " DataNavigateUrlFormatString= "ShowNews.aspx?news_id={0}&other={1} " />


GridView DataSource
绑定了吗?
------解决方案--------------------