K
Kbalz
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="gvSearchResults" HorizontalAlign="Center"
AllowSorting="true" runat="server"
Width="100%" Visible="true"
AutoGenerateColumns="false" ForeColor="Black"
OnRowCommand="gvSearchResults_RowCommand">
<HeaderStyle
HorizontalAlign="Center" Font-Size="Small" />
<RowStyle HorizontalAlign="Center"
Font-Size="Smaller" />
<EditRowStyle
HorizontalAlign="Center" Font-Size="Smaller" /><EmptyDataRowStyle Font-
Bold="True" Font-Size="Medium" ForeColor="Red"
HorizontalAlign="Center"
VerticalAlign="Middle"
Height="80px" BackColor="#EEEEEE" />
<EmptyDataTemplate>
No Results...
</EmptyDataTemplate>
</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.DataField = dataSourceName;
columnToAdd.HeaderText = dataSourceHeaderName;
gvSearchResults.Columns.Add(columnToAdd);
But I get this overload error:
CS1502: The best overloaded method match for
'System.Web.UI.WebControls.DataControlFieldCollection.Add(System.Web.UI.WebControls.DataControlField)'
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/ArticleDetails.aspx?articleID=88
http://www.dotnetbips.com/articles/56fadcb9-ee8b-4170-a6ad-cd4f38222bcb.aspx
http://aspalliance.com/785
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="gvSearchResults" HorizontalAlign="Center"
AllowSorting="true" runat="server"
Width="100%" Visible="true"
AutoGenerateColumns="false" ForeColor="Black"
OnRowCommand="gvSearchResults_RowCommand">
<HeaderStyle
HorizontalAlign="Center" Font-Size="Small" />
<RowStyle HorizontalAlign="Center"
Font-Size="Smaller" />
<EditRowStyle
HorizontalAlign="Center" Font-Size="Smaller" /><EmptyDataRowStyle Font-
Bold="True" Font-Size="Medium" ForeColor="Red"
HorizontalAlign="Center"
VerticalAlign="Middle"
Height="80px" BackColor="#EEEEEE" />
<EmptyDataTemplate>
No Results...
</EmptyDataTemplate>
</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.DataField = dataSourceName;
columnToAdd.HeaderText = dataSourceHeaderName;
gvSearchResults.Columns.Add(columnToAdd);
But I get this overload error:
CS1502: The best overloaded method match for
'System.Web.UI.WebControls.DataControlFieldCollection.Add(System.Web.UI.WebControls.DataControlField)'
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/ArticleDetails.aspx?articleID=88
http://www.dotnetbips.com/articles/56fadcb9-ee8b-4170-a6ad-cd4f38222bcb.aspx
http://aspalliance.com/785