This is a migrated thread and some comments may be shown as answers.

Problem in dynamically adding Properties in RadGrid Control

1 Answer 84 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ravichandran
Top achievements
Rank 1
Ravichandran asked on 11 Oct 2010, 03:24 PM
Hi Experts,

Error: Multiple controls with the same ID 'ctl00' were found. Trace requires that controls have unique IDs.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Multiple controls with the same ID 'ctl00' were found. Trace requires that controls have unique IDs.

In .aspx file I am having one table 
  <asp:Table ID="mytable" runat="server" HorizontalAlign="Center" Width="100%" CellPadding="4"
                                        CellSpacing="0" BorderStyle="None">
                                    </asp:Table>

for the above table I am dynamically adding the RadGrid with properties in the class file.Refer the code below

 public class Home : MyHtmlControls
    {
     private RadGrid HVRGrid111 = new RadGrid();

private void GetClassicRadgrid(ref HtmlTableCell MyCell)
        {
        

            DataSet myobjdr = new DataSet();
            DataSet myds = new DataSet();
            string _DelviewUrl;
            string _EditUrl;
            string delJavaScriptStr;
            string _hprlnkUrl;


            GridBoundColumn mybound = new GridBoundColumn();
            GridTemplateColumn myTemplate;
            GridHyperLinkColumn myHyperLink = new GridHyperLinkColumn();

            try
            {
                delJavaScriptStr = "<script language=\"javascript\">\n";
                delJavaScriptStr += "<!--\n";
                delJavaScriptStr += "function Delete_" + _TableName + "(option,option1,option2,option3,option4,option5,option6,option7,option8)\n";
                delJavaScriptStr += "{\n";

                delJavaScriptStr += "var del = window.confirm('Are You Sure you want to delete ?');\n";
                delJavaScriptStr += "if (del)\n";
                delJavaScriptStr += "{\n";
                delJavaScriptStr += "openwin1('Delete.aspx?dbmode=del&tblid=' + option + '&Mode=' + option1 + '&UrlPath=' + option2 + '&uMode=' + option4 + '&uColid='+ option5 + '&uid='+ option6 + '&id=' + option3 + '&uTabid=' + option7+'&rMode='+option8,'400','200','no');\n";
                delJavaScriptStr += "}\n";

                delJavaScriptStr += "}\n";
                delJavaScriptStr += "//-->\n";
                delJavaScriptStr += "</script>";
                Form.Page.RegisterStartupScript("Delete_" + _TableName, delJavaScriptStr);


           
                GridHyperLinkColumn Delhyper = new GridHyperLinkColumn();
                GridHyperLinkColumn hyper = new GridHyperLinkColumn();
                GridHyperLinkColumn eDIT = new GridHyperLinkColumn();

                if (Isallowed("D", Session["userid"].ToString(), _ColId, "V"))
                {
                    _DelviewUrl = "javascript:Delete_" + _TableName + "('" + _addEditTable + "','Del','" + IncomingURL + "','{0}','hm','" + _ColId + "','0','" + _Tabid + "','hm');";
                    //_DelviewUrl=IncomingURL +"?mode=hm&dbmode=del&TabId="+_ForTabId+"&ColID="+_ColId+"&pkval={0}&userid="+_userid+"&username="+_username;
                    Delhyper.DataNavigateUrlFormatString = _DelviewUrl;
                    Delhyper.DataNavigateUrlFields = _PrimaryColumn.Split('/');
                    Delhyper.HeaderText = "Delete";
                    Delhyper.HeaderStyle.CssClass = ReadXML(_ThemeConfigName, "cssfor", "GridHead", "cssname", "name");
                    Delhyper.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
                    Delhyper.Text = "<img src=\"" + _ThemeImagesPath + ReadXML(_ThemeImagesName, "imgfor", "DeleteImage", "imgName", "name") + "\" border=0 alt='Delete'>";
                    Delhyper.NavigateUrl = _DelviewUrl;
                    HVRGrid111.Columns.Add(Delhyper);
                }

                if (Isallowed("V", Session["userid"].ToString(), _ExtendedViewId, "V"))
                {
                    if (_ExtendedViewId.Trim() == "0")
                    {
                        _ExtendedViewUrl = "javascript:alert('View Form Is Not Available For This tab!')";
                    }
                    else
                    {
                        _ExtendedViewUrl = _ExtendedViewUrl + "&id={0}";
                    }
                    hyper.DataNavigateUrlFormatString = _ExtendedViewUrl;
                    hyper.DataNavigateUrlFields = _PrimaryColumn.Split('/');
                    hyper.HeaderText = "View";
                    hyper.HeaderStyle.CssClass = ReadXML(_ThemeConfigName, "cssfor", "GridHead", "cssname", "name");
                    hyper.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
                    hyper.Text = "<img src=\"" + _ThemeImagesPath + ReadXML(_ThemeImagesName, "imgfor", "ExtView", "imgName", "name") + "\" border=0 alt='View'>";
                    hyper.NavigateUrl = _ExtendedViewUrl;
                    HVRGrid111.Columns.Add(hyper);
                }
                if (Isallowed("E", Session["userid"].ToString(), _ColId, "V"))
                {
                    if (_addEditTable.Trim() == "0")
                    {
                        _EditUrl = "javascript:alert('Add Edit Form Is Not Available For This tab!')";
                    }
                    else
                    {
                        _EditUrl = "javascript:Open_addedit_new_" + _TableName + "('" + _addEditTable + "','rd','" + IncomingURL + "','{0}','hm','" + _ColId + "','0','" + _Tabid + "','hm');";
                    }

                    eDIT.DataNavigateUrlFields = _PrimaryColumn.Split('/');
                    eDIT.DataNavigateUrlFormatString = _EditUrl;
                    //eDIT.DataNavigateUrlFields = _PrimaryColumn;
                    eDIT.HeaderText = "Edit";
                    eDIT.HeaderStyle.CssClass = ReadXML(_ThemeConfigName, "cssfor", "GridHead", "cssname", "name");
                    eDIT.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
                    eDIT.Text = "<img src=\"" + _ThemeImagesPath + ReadXML(_ThemeImagesName, "imgfor", "Edit", "imgName", "name") + "\" border=0 alt='Edit'>";
                    eDIT.NavigateUrl = _ExtendedViewUrl;
                    //HomeViewGrid.Columns.Add(eDIT);
                    HVRGrid111.Columns.Add(eDIT);
                }


                myds = GetDataSet(genview());

            
                myobjdr = GetDataSet("select * from tableinfo where  COLINFODETAILSID='" + _ForTableId + "' and visibility <> 'hdd'  order by ORDERFLD ");

                HVRGrid111.AutoGenerateColumns = false;
                HVRGrid111.AllowPaging = true;
                HVRGrid111.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;
                HVRGrid111.Width = Unit.Percentage(98);
                HVRGrid111.PageSize = 5;
                HVRGrid111.AllowFilteringByColumn = true;
                HVRGrid111.AllowSorting = true;
                HVRGrid111.ShowFooter = true;
                HVRGrid111.HeaderStyle.Width = Unit.Pixel(150);
                HVRGrid111.ClientSettings.ReorderColumnsOnClient = true;
                HVRGrid111.ClientSettings.AllowDragToGroup = true;
                HVRGrid111.ClientSettings.AllowColumnsReorder = true;
                HVRGrid111.ClientSettings.Scrolling.AllowScroll = true;
                HVRGrid111.ClientSettings.Scrolling.UseStaticHeaders = true;
                HVRGrid111.ClientSettings.Selecting.AllowRowSelect = true;

               
                HVRGrid111.DataSource = myds.Tables["cnpl"];
                HVRGrid111.DataBind();



                ViewState["DS"] = myds;
                for (int intcount = 0; intcount < HomeViewGrid.PageCount; intcount++)
                {
                    LI = new ListItem();
                    LI.Value = Convert.ToString(intcount);
                    LI.Text = Convert.ToString(intcount + 1) + " Of " + HomeViewGrid.PageCount.ToString();
                    MyViewPagination_DRP.Items.Add(LI);
                    //EnableLinks();
                }
              
                MyCell.Controls.Add(HVRGrid111 );
                if (myds.Tables[0].Rows.Count == 0)
                {
                    HtmlTable L1Table;
                    HtmlTableRow L1Row;
                    HtmlTableCell L1Cell;
                    L1Table = new HtmlTable();
                    L1Table.Attributes["class"] = ReadXML(_ThemeConfigName, "cssfor", "QcTable", "cssname", "name");
                    L1Table.Width = Unit.Percentage(100).ToString();
                    L1Table.Align = HorizontalAlign.Center.ToString();
                    L1Table.CellPadding = 2;
                    L1Table.CellSpacing = 0;
                    L1Table.Border = 0;
                    L1Table.BorderColor = ReadXML(_ThemeConfigName, "cssfor", "BorderCol", "cssname", "name");
                    L1Row = new HtmlTableRow();
                    L1Row.Align = HorizontalAlign.Center.ToString();
                    L1Row.VAlign = VerticalAlign.Middle.ToString();
                    L1Row.Attributes["class"] = ReadXML(_ThemeConfigName, "cssfor", "GridItem", "cssname", "name");
                    L1Cell = new HtmlTableCell();
                    L1Cell.Align = HorizontalAlign.Center.ToString();
                    L1Cell.InnerHtml = "<span class=\"" + ReadXML(_ThemeConfigName, "cssfor", "Error", "cssname", "name") + "\"> No Records Found !!!</span>";
                    L1Row.Cells.Add(L1Cell);
                    L1Table.Rows.Add(L1Row);
                    MyCell.Controls.Add(L1Table);

                }
               
            }
            catch (Exception ex)
            {
                PutErrorPage(ref MyCell, "Error While Creating View !!!!<br>" + ex.ToString());
            }
           
}

If I execute the above code I am getting the error mentioned above. This error is the blocking stone for my project .Please help me to resolve this error. 


Thanks in advance!
Ravi

1 Answer, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 14 Oct 2010, 01:13 PM
Hello,

Please verify if you correctly create the Grid structure using the instructions in the following help topic.

Regards,
Maria Ilieva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Ravichandran
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Share this question
or