gpt4 book ai didi

c# - ASP.NET 动态添加列到 Gridview

转载 作者:太空狗 更新时间:2023-10-29 18:20:09 26 4
gpt4 key购买 nike

如何根据条件向 GridView 动态添加一些列?

  <asp:gridview id="CustomersGridView" 
datasourceid="CustomersSource"
autogeneratecolumns="true"
emptydatatext="No data available."
runat="server">

<columns>
<asp:boundfield datafield="CustomerID" headertext="Customer ID"/>
<asp:boundfield datafield="CompanyName" headertext="Company Name"/>
<asp:boundfield datafield="Address" headertext="Address"/>
<asp:boundfield datafield="City" headertext="City"/>
<asp:boundfield datafield="PostalCode" headertext="Postal Code"/>
<asp:boundfield datafield="Country" headertext="Country"/>
</columns>
for(int i; i < length; i++)
<asp:boundfield datafield="text" headertext="text"/>
</asp:gridview>

最佳答案

试试这个:

BoundField test = new BoundField();
test.DataField = "New DATAfield Name";
test.Headertext = "New Header";
CustomersGridView.Columns.Add(test);

关于c# - ASP.NET 动态添加列到 Gridview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21754144/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com