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

Cannot get data from table within radpanel

4 Answers 130 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
cyfirst
Top achievements
Rank 1
cyfirst asked on 12 Nov 2009, 11:40 PM
Hi,
I am not having much luck getting input data from a table that is dynamically created within a radpanel and am hoping someone could tell me what I am doing wrong. 

 <! -- Index data -----------> 
           <telerik:RadPanelBar runat="server" ID="RadPanelBar1"   
              ExpandMode="FullExpandedItem" Width="98%" Height="50%" > 
               <Items> 
                    <telerik:RadPanelItem Expanded="True" Text="Index Information"  Selected="true">   
                        <Items> 
                            <telerik:RadPanelItem Value="IndexInformation" > 
                                <ItemTemplate> 
                                    <asp:Table ID="IndexTable" runat="server"  EnableViewState="false" >                  
                                    </asp:Table> 
                                </ItemTemplate> 
                            </telerik:RadPanelItem> 
                        </Items> 
                    </telerik:RadPanelItem> 
                </Items> 
           </telerik:RadPanelBar>       

The table (IndexTable) is created dynamically
                IndexTable.Rows.Clear();  
                //load the custom indexes  
                foreach (int idx in ur.AllIndexes)  
                {  
                    if (rd.IndexMap.ContainsKey(idx))  
                    {  
                        CIndex cIndex = rd.IndexMap[idx];  
 
                        Label lbl = new Label();  
                        lbl.ID = idx.ToString() + "Label";  
                        lbl.Text = cIndex.IndexComponents[1].Label;  
                        lbl.Visible = true;  
                          
                        TableRow tr = new TableRow();  
 
                        // Create column 1    
                        TableCell td1 = new TableCell();  
                        // Create a label control dynamically    
                        Label _label = new Label();  
                        _label.ID = idx.ToString() + "Label";  
                        _label.Text = cIndex.IndexComponents[1].Label;  
                        // Add control to the table cell    
                        td1.Controls.Add(_label);  
 
                        // Create column 2    
                        TableCell td2 = new TableCell();  
                        td2.Visible = true;
                     }  
                     // Add cell to the row  tr.Cel  
                     tr.Cells.Add(td1);  
                     tr.Cells.Add(td2);  
                     // Add row to the table.   
                     IndexTable.Rows.Add(tr);  
                }  
 
 

The table is displayed just fine but I can't retrieve any of the data that I input into cell 2.  I have a "Submit" button that calls javascript to get the data but all I get is the label data, cell 1. 
 <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">  
      <script type="text/javascript">  
          function GetIndexData() {  
              var test = "";  
              var tblIndex = $get('<%= ((Table)RadPanelBar1.FindItemByValue("IndexInformation").FindControl("IndexTable")).ClientID %>');  
            
              var RowsLength = tblIndex.rows.length;  
              for (var i = 0; i < RowsLength; i++) {  
                  var oCells = tblIndex.rows.item(i).cells;  
                  var CellsLength = oCells.length;  
                  for (var j = 0; j < CellsLength; j++) {  
                      alert(oCells.item(j).innerHTML);  
                  }  
              }  
          }  
      </script> 
    </telerik:RadCodeBlock>    

 I know I must be doing something wrong but I don't know what.  Can anyone help me?

Thanks 

4 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 18 Nov 2009, 01:49 PM
Hello cyfirst,

Probably because you do not have anything in cell2 (td2)?

I tested with this code and it worked fine:

telerik:RadPanelBar runat="server" ID="RadPanelBar1"  
  Width="98%" Height="50%" >
   <Items>
        <telerik:RadPanelItem Expanded="True" Text="Index Information" >  
            <Items>
                <telerik:RadPanelItem Value="IndexInformation" Expanded="True" >
                    <ItemTemplate>
                        <asp:Table ID="IndexTable" runat="server"  EnableViewState="true" >                 
                        </asp:Table>
                    </ItemTemplate>
                </telerik:RadPanelItem>
            </Items>
        </telerik:RadPanelItem>
    </Items>
</telerik:RadPanelBar>             
     
    </div>
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
    <input type="button" value="getindexdata" onclick="GetIndexData()" />
     <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server"
      <script type="text/javascript"
          function GetIndexData() { 
              var test = ""; 
              var tblIndex = $get('<%= ((Table)RadPanelBar1.FindItemByValue("IndexInformation").FindControl("IndexTable")).ClientID %>'); 
             
              var RowsLength = tblIndex.rows.length; 
              for (var i = 0; i < RowsLength; i++) { 
                  var oCells = tblIndex.rows.item(i).cells; 
                  var CellsLength = oCells.length; 
                  for (var j = 0; j < CellsLength; j++) { 
                      alert(oCells.item(j).innerHTML); 
                  
              
          
      </script>
    </telerik:RadCodeBlock>

protected void Button1_Click(object sender, EventArgs e)
    {
        RadPanelItem item = RadPanelBar1.FindItemByValue("IndexInformation");
        Table IndexTable = item.FindControl("IndexTable") as Table;
 
        IndexTable.Rows.Clear();
        //load the custom indexes 
        for (int idx = 0; idx < 3; idx++ )
        {           
            Label lbl = new Label();
            lbl.ID = idx.ToString() + "Label";
            lbl.Text = "Label" + idx.ToString();
            lbl.Visible = true;
 
            TableRow tr = new TableRow();
 
            // Create column 1   
            TableCell td1 = new TableCell();
            // Create a label control dynamically   
            Label _label = new Label();
            _label.ID = idx.ToString() + "Label2";
            _label.Text = "LABEL" + idx.ToString();
            // Add control to the table cell   
            td1.Controls.Add(_label);
 
            // Create column 2   
            TableCell td2 = new TableCell();
            td2.Controls.Add(lbl);
            td2.Visible = true;
            // Add cell to the row  tr.Cel 
            tr.Cells.Add(td1);
            tr.Cells.Add(td2);
            // Add row to the table.  
            IndexTable.Rows.Add(tr);
        
    }

Note that I am adding the lbl control to the td2 controls collection and now everything is working.

Kind regards,
Veselin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
cyfirst
Top achievements
Rank 1
answered on 18 Nov 2009, 03:03 PM
Hi,

Thanks for the reply.  I must not have added the code that adds to the table cell 2.  It can be any of the following depending on the data being sent.  I cannot get the input values from these controls. I must not be looking in the correct place to get the value.
if (cIndex.IndexComponents[1].Format == "05")  
{  
   // date picker  
   RadDatePicker _rdp = new RadDatePicker();  
   _rdp.ID = "rdp_Index" + idx.ToString();  
   _rdp.SharedCalendar = SharedCalendar;  
   // Add control to the table cell    
  td2.Controls.Add(_rdp);  
}  
else  
{  
   if (cIndex.ValidValues != null)  
   {  
      RadComboBox _rcb = new RadComboBox();  
      _rcb.ID = "rcb_Index" + idx.ToString();  
      //populate the values  
      _rcb.MaxHeight = 100;  
      defaultItem = new RadComboBoxItem();  
      defaultItem.Text = "";  
      defaultItem.Value = "00";  
      _rcb.Items.Add(defaultItem);  
      defaultItem = null;  
      foreach (KeyValuePair<int, string> kvp in cIndex.ValidValues)  
      {  
          RadComboBoxItem item = new RadComboBoxItem();  
          item.Text = kvp.Value;  
          item.Value = kvp.Key.ToString();  
          _rcb.Items.Add(item);  
      }  
 
      // Add control to the table cell    
      td2.Controls.Add(_rcb);  
      }  
      else  
      {  
        RadTextBox _rtb = new RadTextBox();  
        _rtb.ID = "rtb_Index" + idx.ToString();  
        td2.Controls.Add(_rtb);  
      }  
  }  
  // Add cell to the row  tr.Cell 
  tr.Cells.Add(td1);  
  td2.Visible = true;  
  tr.Cells.Add(td2);  
                          
  // Add row to the table.   
  IndexTable.Rows.Add(tr);  
  }  
when I display the contents of the innerhtml I get the following for the label (innerlabel.gif) and textbox (inner text.gif), label works just fine but I can't get the data from the textbox.  I see it is in there but I don't know how to retrieve it.
I also tried to looked at the table controls in a buttonClick event but the table does not show any rows. Am I missing a key concept here?
Thanks & Regards 
0
Veselin Vasilev
Telerik team
answered on 20 Nov 2009, 01:07 PM
Hello cyfirst,

Here is what I have done:

// Create column 2   
TableCell td2 = new TableCell();
RadTextBox _rtb = new RadTextBox();
_rtb.ID = "rtb_Index" + idx.ToString();
td2.Controls.Add(_rtb);

<script type="text/javascript"
  function GetIndexData() { 
      var test = ""
      var tblIndex = $get('<%= ((Table)RadPanelBar1.FindItemByValue("IndexInformation").FindControl("IndexTable")).ClientID %>');
      var $ = $telerik.$;
      var RowsLength = tblIndex.rows.length; 
      for (var i = 0; i < RowsLength; i++) { 
          var oCells = tblIndex.rows.item(i).cells; 
          var CellsLength = oCells.length;
          for (var j = 0; j < CellsLength; j++) {                     
              var textboxID = $("SPAN", oCells.item(j))[0].id.replace("_wrapper", "");
              var textbox = $find(textboxID);
              if (textbox) {
                  alert(textbox.get_value());
              }
          
      
  
</script>


Kind regards,
Veselin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
cyfirst
Top achievements
Rank 1
answered on 23 Nov 2009, 09:43 PM
Thank you for your time and effort but this throws a javascript error "Microsoft JScript runtime error: '0' is null or not an object".  I guess I'll try something else.
Regards,
Tags
PanelBar
Asked by
cyfirst
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
cyfirst
Top achievements
Rank 1
Share this question
or