I have a user control that has a gridview in it. I am dynamically
setting up its datasource and columns based on an XML file.
I have everything done except adding columns to the gridview, so that
the user only sees certain columns based on the XML file.
In my ASCX page I simply defined the gridview
<asp:GridView ID="gvSearchRes ults" HorizontalAlign ="Center"
AllowSorting="t rue" runat="server"
Width="100%" Visible="true"
AutoGenerateCol umns="false" ForeColor="Blac k"
OnRowCommand="g vSearchResults_ RowCommand">
<HeaderStyle
HorizontalAlign ="Center" Font-Size="Small" />
<RowStyle HorizontalAlign ="Center"
Font-Size="Smaller" />
<EditRowStyle
HorizontalAlign ="Center" Font-Size="Smaller" /><EmptyDataRowS tyle Font-
Bold="True" Font-Size="Medium" ForeColor="Red"
HorizontalAlign ="Center"
VerticalAlign=" Middle"
Height="80px" BackColor="#EEE EEE" />
<EmptyDataTempl ate>
No Results...
</EmptyDataTempla te>
</asp:GridView>
I also have a button, that when clicked, checks the XML file, and
builds the query string, and adds columns to the gridview.. so in the
code behind I have this
gvSearchResults .Columns.Clear( );
BoundColumn columnToAdd = new BoundColumn();
columnToAdd.Dat aField = dataSourceName;
columnToAdd.Hea derText = dataSourceHeade rName;
gvSearchResults .Columns.Add(co lumnToAdd);
But I get this overload error:
CS1502: The best overloaded method match for
'System.Web.UI. WebControls.Dat aControlFieldCo llection.Add(Sy stem.Web.UI.Web Controls.DataCo ntrolField)'
has some invalid arguments
Every example I check on line says those four lines of code is all
that is needed to dynamically add columns.. what gives..??
http://www.gridviewguy.com/ArticleDe...x?articleID=88
http://www.dotnetbips.com/articles/5...f38222bcb.aspx
http://aspalliance.com/785