Dynamic Row in Radgrid

3 posts, 0 answers
  1. James Deepak
    James Deepak avatar
    12 posts
    Member since:
    Feb 2010

    Posted 23 Feb 2010 Link to this post

    Hi,
         I need to create an advertisement banner between the radgrid rows, so i checking for the rowcount and if it is a specific row then im dynmically creating a table cell and rows and tried to fit it into the table but i coulnt see the banner image,  though the code was successfully built. Below is the code im using to implement the functionality
                    Please help with this issue. Thanks in advance.

      if ((e.Item.RowIndex == 2)) 
                        { 
                            /* Code to add the image banner in between the rows - Start*/ 
                            TableCell tCell = new TableCell(); 
                            ImageButton img = new ImageButton(); 
     
                            img.ID = "ImageBannerID"


                            img.ImageUrl = hdnSpecialImageSrc.Value; 
                            img.PostBackUrl = hdnSpecialImageRedirect.Value; 
                            img.Style.Add("cursor""hand"); 
                            img.Style.Add("margin-top""5px"); 
                            img.Style.Add("margin-bottom""5px"); 
                            tCell.Controls.Add(img); 
     
                            Table tblGrid = ((Table)(this.RadGrid1.MasterTableView.Controls[0]));                       
                            int intIndex = tblGrid.Rows.GetRowIndex(e.Item); 
                            Telerik.Web.UI.GridItem gvrSubHeading = new Telerik.Web.UI.GridItem(this.RadGrid1.MasterTableView, intIndex, intIndex, Telerik.Web.UI.GridItemType.Separator);                                              
     

                            tCell.ColumnSpan = this.RadGrid1.MasterTableView.Columns.Count; 
                            gvrSubHeading.Cells.Add(tCell);                         
                            tblGrid.Controls.AddAt(intIndex, gvrSubHeading); 
     
                           
                            /*End of Coding*/ 
                        } 
  2. Nikita Gourme
    Nikita Gourme avatar
    318 posts
    Member since:
    May 2006

    Posted 24 Feb 2010 Link to this post

    James, I think that creating RadGrid unbound rows in this way and adding them to the Controls collection of the master table is not supported. To inject an image button and other controls in a certain grid row only, try to use a template column and add the image dynamically inside the ItemCreated event handler of the grid.

    Nikita
  3. Gajanan
    Gajanan  avatar
    49 posts
    Member since:
    May 2010

    Posted 17 Aug 2015 in reply to Nikita Gourme Link to this post

    Dear all,
    My requirement is Bind the grid dynamic , and add the controls like Text Box And rad Como box at run time by Item value.
    so far have done the control adding and now my grid is ready to take values from user , 
    but when user selected value from rad combo box (dynamic added control in grid), and click the save button i cannot find the Rad Combo box 
    pls suggest me the way how to get the values for dynamically added controls in Rad-grid on button click.
    below are the steps i followed
    1. Added Grid in Aspx. with Autogenerated Column = true
    2. On Item created event added dynamic controls in Grid. 
    3. bind the data to ad combo box (dynamic added control in grid) 
    4. on save Button i have to save the selected values from rad combo box (dynamic added control in grid), to data base
    in above step 1 to 3 are done , but step 4 making me trouble .

    below is code for button click.
    protected void btnSaveAll_Click(object sender, EventArgs e)
    {
        Questionnaire MyQue = Questionnaire.getQuestionnaire(mQuestionnaireid); 
        ArrayList ColumnLst = GetColumnList();
                    Dictionary<string,string> RowSplitValue = new Dictionary<string,string>();
                    foreach (GridEditableItem Item in rgPivotQuestionnaireResult.MasterTableView.Items)
                    {
                        foreach (GridColumn Column in rgPivotQuestionnaireResult.MasterTableView.RenderColumns)
                        {
                            if (ColumnLst.Contains(Column.UniqueName))
                            {
                                //RowSplitValue = new Dictionary<string, string>(Item.SavedOldValues[Column.UniqueName]);
                                if (Item[Column].Controls.Count > 0)
                                {
                                    Control ItemControle= new Control();
                                    ItemControle = Item[Column].Controls[0];
                                    if (ItemControle is TextBox)
                                    {
                                        TextBox TxtBx = (TextBox)Item[Column].Controls[0];
                                    }
                                    if (Item[Column].Controls.Count > 1)
                                    {
                                        ItemControle = Item[Column].Controls[1];
                                        if (ItemControle is RadComboBox)
                                        {
                                            RadComboBox RCB = (RadComboBox)Item[Column].Controls[1];
                                              MyQue .Answervalue = RCB.SelectedValue;
                                        }
                                    }
                                }
                            }
                        }
                    }
       MyQue .Save();
    }
Back to Top