****请教高手:.GridView的列想根据用户查询内容的不同来设置各个列的位置?******
请教高手:.NET 2.0 C#中的GridView控件的列想根据用户查询内容的不同来设置各个列的位置? 有什么代码能实现各个列位置的替换? 先谢谢了。
<Columns>
<asp:BoundField DataField= "fanshi " HeaderText= "方式 " SortExpression= "fanshi " />
<asp:BoundField DataField= "media " HeaderText= "媒体 " SortExpression= "media " />
<asp:BoundField DataField= "riqi " HeaderText= "时段 " SortExpression= "riqi " />
<asp:BoundField DataField= "xxhd " HeaderText= "宣传活动 " SortExpression= "xxhd " />
<asp:BoundField DataField= "xxnr " HeaderText= "宣传内容 " SortExpression= "xxnr " />
<asp:BoundField DataField= "times " HeaderText= "次数 " />
<asp:BoundField DataField= "places " HeaderText= "地点 " />
<asp:BoundField DataField= "zxdw " HeaderText= "执行单位 " SortExpression= "zxdw " />
<asp:BoundField DataField= "opendate " DataFormatString= "{0:yyyy-MM-dd} " HeaderText= "开始日期 "
HtmlEncode= "False " />
<asp:BoundField DataField= "enddate " DataFormatString= "{0:yyyy-MM-dd} " HeaderText= "结束日期 "
HtmlEncode= "False " />
<asp:BoundField DataField= "memoshi " HeaderText= "备注 " SortExpression= "memoshi " >
<HeaderStyle Width= "40px " />
</asp:BoundField>
<asp:HyperLinkField HeaderText= "广告欣赏 " Target= "_blank " Text= "点击 " DataNavigateUrlFields= "URl " DataNavigateUrlFormatString= "upfiles\{0} " >
<HeaderStyle Width= "60px " />
</asp:HyperLinkField>
<asp:BoundField DataField= "URL " HeaderText= "URL " SortExpression= "URL " >
<ControlStyle CssClass= "hidden " />
<ItemStyle CssClass= "hidden " />
<HeaderStyle CssClass= "hidden " />
<FooterStyle CssClass= "hidden " />
</asp:BoundField>
</Columns>
[解决办法]
每次查询的时候,动态生成列,
或者交换列:
DataControlField temp=GridView1.Columns[0];
GridView1.Columns[0] = GridView1.Columns[1];
GridView1.Columns[1] = temp;
只方法没有测试,自己试试吧。