user3305953 user3305953 - 1 year ago 177
ASP.NET (C#) Question

ASP.NET dynamically add column to Gridview

how can I add to GridView dynamically some columns based on condition?

<asp:gridview id="CustomersGridView"
emptydatatext="No data available."

<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"/>
for(int i; i < length; i++)
<asp:boundfield datafield="text" headertext="text"/>

Answer Source

Try this:

BoundField test = new BoundField();
test.DataField = "New DATAfield Name";
test.Headertext = "New Header";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download