I am creating a RadGrid in C# and adding it to a placeholder.
The problem I am having is accessing the RadGrid in my other functions.
I get the following error on "Grid1.PageSize = 1;" when I build the solution
Error 1 'System.Web.UI.ControlCollection' does not contain a definition for 'Grid1' and no extension method 'Grid1' accepting a first argument of type 'System.Web.UI.ControlCollection' could be found (are you missing a using directive or an assembly reference?)
RadGrid RadGrid1 = new RadGrid();
RadGrid1.ID = "RadGrid1";
// Add the RadGrid instance to the controls
this.PlaceHolder1.Controls.Add(RadGrid1);
RadGrid1.DataSourceID = "SqlDataSource1";
RadGrid1.MasterTableView.DataKeyNames = new string[] { "Jobnumber" };
RadGrid1.Skin = "Default";
RadGrid1.Width = Unit.Percentage(100);
RadGrid1.PageSize = 15;
RadGrid1.AllowPaging = true;
RadGrid1.AllowSorting = true;
RadGrid1.AllowFilteringByColumn = true;
RadGrid1.AutoGenerateColumns = false;
RadGrid1.GridLines = GridLines.Both;
RadGrid1.ItemCommand += new GridCommandEventHandler(RadGrid1_ItemCommand);
//Add columns
GridBoundColumn boundColumn;
foreach (DataRow dr in dt.Rows)
{
//Add column
boundColumn = new GridBoundColumn();
boundColumn.DataField = dr["DataField"].ToString().Trim(); // Initalize the DataField value.
boundColumn.HeaderText = dr["HeaderText"].ToString().Trim(); // Initialize the HeaderText field value.
boundColumn.HtmlEncode = false;
boundColumn.ReadOnly = true;
boundColumn.SortExpression = dr["SortExpression"].ToString().Trim();
boundColumn.HeaderStyle.CssClass = "headerstyle";
if (dr["align"].ToString().Trim().ToUpper().Equals("RIGHT"))
boundColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Right;
if (dr["align"].ToString().Trim().ToUpper().Equals("LEFT"))
boundColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Left;
if (dr["align"].ToString().Trim().ToUpper().Equals("CENTER"))
boundColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
if (dr["width"].ToString().Length == 0)
boundColumn.HeaderStyle.Width = 100;
else
boundColumn.HeaderStyle.Width = Convert.ToInt32(dr["width"].ToString().Trim());
RadGrid1.MasterTableView.Columns.Add(boundColumn);
}
<
asp:PlaceHolder
ID
=
"PlaceHolder1"
runat
=
"server"
/>
The problem I am having is accessing the RadGrid in my other functions.
protected void btn1AusePrint_Command(GridCommandEventArgs e)
{
RadGrid Grid1 = (RadGrid)PlaceHolder1.FindControl("RadGrid1");
Grid1.PageSize = 1; // Set to one record per page when displaying document
:
:
}
I get the following error on "Grid1.PageSize = 1;" when I build the solution
Error 1 'System.Web.UI.ControlCollection' does not contain a definition for 'Grid1' and no extension method 'Grid1' accepting a first argument of type 'System.Web.UI.ControlCollection' could be found (are you missing a using directive or an assembly reference?)