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

dynamic itemtemplate using radnumeric text box

4 Answers 82 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kshitiz
Top achievements
Rank 1
Kshitiz asked on 09 May 2012, 06:47 AM
 am creating an itemtemplate all dynamic and adding text box ...i also looked to this link: http://www.telerik.com/help/aspnet-ajax/grid-programmatic-creation.html but the coding is too dense ..  

please help me with my code 

  int colCnt = ds.Tables[0].Columns.Count;
            int rowCnt = ds.Tables[0].Rows.Count;

 GridBoundColumn boundColumn;
   boundColumn = new GridBoundColumn();
           

 RadGrid1.MasterTableView.Columns.Add(boundColumn);
            boundColumn.DataField = ds.Tables[0].Columns[0].ColumnName ;
            boundColumn.HeaderText = ds.Tables[0].Columns[0].ColumnName;
            GridTemplateColumn templateColumn;
            for (int i = 1; i < colCnt; i++)
            {
             
                templateColumn = new GridTemplateColumn();
                templateColumn . --> am clueless over here ....can u guyz me ! 

                RadGrid1.MasterTableView.Columns.Add(templateColumn);
                boundColumn.DataField = ds.Tables[0].Columns[i].ColumnName;
                boundColumn.HeaderText = ds.Tables[0].Columns[i].ColumnName;
            }

4 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 09 May 2012, 09:41 AM
Hello Kshitiz,

Please check "Creating template columns programmatically" in Programmatic Creation.

Note : do not forget to give different unique name to columns.

Thanks,
Jayesh Goyani
0
Kshitiz
Top achievements
Rank 1
answered on 09 May 2012, 10:04 AM
BusinessLogic.TotalSeats objcat = new BusinessLogic.TotalSeats();
            ds = objcat.GetTotalSeats();
            grid.DataSource = ds;
    int colCnt = ds.Tables[0].Columns.Count;
            int rowCnt = ds.Tables[0].Rows.Count;
  
            GridBoundColumn boundColumn;
            boundColumn = new GridBoundColumn();
            grid.MasterTableView.Columns.Add(boundColumn);
            boundColumn.DataField = ds.Tables[0].Columns[0].ColumnName;
            boundColumn.HeaderText = ds.Tables[0].Columns[0].ColumnName;
            GridTemplateColumn templateColumn = new GridTemplateColumn();


            grid.MasterTableView.EnableColumnsViewState = false;
            for (int i = 1; i < colCnt; i++)
            {
                string templateColumnName = ds.Tables[0].Columns[1].ColumnName;
                templateColumn.ItemTemplate = new MyTemplate(templateColumnName);
                templateColumn.HeaderText = templateColumnName;
                templateColumn .UniqueName = templateColumnName;
                templateColumn.DataField = templateColumnName;
                grid.MasterTableView.Columns.Add(templateColumn);
               

IN THIS CODE AM GETTING the data as
table     col1 col1 col1 col1    --> col1 is getting repeated ...am not able to change  also in col1 i cant fetch any value ..
data1
data2
            }


            grid.AllowPaging = true;
            grid.PageSize = 7;
            grid.Skin = "Outlook";
            PlaceHolder1.Controls.Add(grid);
        }
        private class MyTemplate : ITemplate
        {


       


            protected RadNumericTextBox textBox;


            private string colname;
            public MyTemplate(string cName)
            {
                colname = cName;
            }
            public void InstantiateIn(System.Web.UI.Control container)
         {
                    
                 textBox = new RadNumericTextBox();
                 textBox.ID = ""; ---> getting error here Dynamic controls - Multiple Controls with the same ID



                }

            }



        }


GUYZ PLEASE HELP

0
Jayesh Goyani
Top achievements
Rank 2
answered on 09 May 2012, 11:15 AM
Hello,

For that you have to manage your own way.

Please look in below link/demo.
http://www.telerik.com/community/forums/aspnet-ajax/grid/get-checkbox-control-added-dynamically-in-gridtemplate-column.aspx

Thanks,
Jayesh Goyani
0
Kshitiz
Top achievements
Rank 1
answered on 09 May 2012, 12:04 PM
hey am not able to get the data from my sp to to template fields
public void InstantiateIn(System.Web.UI.Control container)
            {
          
                textBox = new RadNumericTextBox();
                textBox.ID = "";
                textBox.Text = "<%# DataBinder.Eval(Container.DataItem,'petroleum') %>";
textBox.DbValue =  "<%# Eval('Mechanical') %>";

}

how can i write dbvalue thrug server side ... and because of my text feilds are empty ..no data is display ..only blank data fileds 
Tags
Grid
Asked by
Kshitiz
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Kshitiz
Top achievements
Rank 1
Share this question
or