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

Add controls to radpanelbaritem

5 Answers 80 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
amni
Top achievements
Rank 1
amni asked on 13 Oct 2013, 10:22 PM
Hi friends,
I success to add controls to the panelbaritem, but cann't find them on button_click.

maybe the problem is with the add of the controls
the add controls event is after I select row on radgrid.


please help me,
thx.


<telerik:RadPane runat="server" ID="PnlData" dir="rtl" text-align="left">
                    <telerik:RadPanelBar ID="radpnlbardata" runat="server"  ExpandMode="FullExpandedItem" Width="100%"  dir="ltr" text-align="left"  Height="100%">
 
                        </telerik:RadPanelBar>
 
                   <div style="width:100%; text-align:center;">
                        <telerik:RadButton ID="btnUpdate" runat="server" Skin="Metro" Text="Update" Width="70px" align="center" visible="false"/>
                        <telerik:RadButton ID="btnadd" runat="server" Skin="Metro" Text="Add" Width="50px" align="center" visible="false"/>
 
                   </div>
               </telerik:RadPane>
dsFieldsDetails = myService.Get_Fields_Details(Request.Params("ObjID"))
 
Dim rdRoot As New Telerik.Web.UI.RadPanelItem
rdRoot.Text = "rbroot"
rdRoot.Expanded = True
rdRoot.PreventCollapse = False
rdRoot.Selected = True
 
For Each row As DataRow In dsFieldsDetails.Tables(0).Rows
   Select Case row(dsFieldsDetails.Tables(0).Columns("field_type_name"))
 
   Case "Int", "smallint", "bigint", "varchar", "nvarchar"
      Dim label1 As New Label
      Dim textbox1 As New RadTextBox
 
      label1.ID = "lbl" + row(dsFieldsDetails.Tables(0).Columns("table_field_name"))
      label1.Text = row(dsFieldsDetails.Tables(0).Columns("table_field_name")) + ":   "
      textbox1.ID = "txt" + row(dsFieldsDetails.Tables(0).Columns("table_field_name"))
      textbox1.Text = ""
 
      rdRoot.Controls.Add(label1)
      rdRoot.Controls.Add(textbox1)
 
   Case "bit"
      Dim checkbox1 As New CheckBox
      checkbox1.ID = "lbl" + row(dsFieldsDetails.Tables(0).Columns("table_field_name"))
      checkbox1.Text = row(dsFieldsDetails.Tables(0).Columns("table_field_name")) + ":   "
      rdRoot.Controls.Add(checkbox1)
 
   End Select
Next


5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 15 Oct 2013, 05:15 AM
Hi amni,

I guess you are trying to add RadPanelItem on OnRowSelected event of RadGrid. The issue you are facing is clicking on Radbutton inside RadPane, it lost all the controls created dynamically.

This is because the controls which is created dynamically(from code behind) should not persist after a postback. Please, note that ASP.NET do not recreate the dynamic controls and you should recreate them in a suitable event according to your needs.

I hope this information helps. Please let me know if you need more help.

Thanks,
Shinu.
0
amni
Top achievements
Rank 1
answered on 16 Oct 2013, 08:02 AM
tahnks Shinu,,
I success load the controls.

I call to function from Page_Load and it's OK.

but if I want to change the parameters in the controls - like textbox.text,
he don't do it.

after I build the controls in panelbaritem on page_load
I click on some row in radgrid and he build the controls again,
but now after postback he show me the controls but I can't find them in the code.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If Not IsPostBack Then
 
            End If
 
            Load_PanelBar()
 
End Sub
0
Shinu
Top achievements
Rank 2
answered on 16 Oct 2013, 11:31 AM
Hi amni,

I have created a similar scenario( created a  TextBox dynamically, added it on RadPanelItem and accessing that TextBox on external RadButton OnClick event). Please have a look into the following code snippet and  let me know if you need help.

ASPX:
<telerik:RadSplitter ID="RadSplitter1" runat="server">
    <telerik:RadPane ID="RadPane1" runat="server">
        <telerik:RadPanelBar ID="RadPanelBar1" runat="server">
        </telerik:RadPanelBar>
    </telerik:RadPane>
</telerik:RadSplitter>
<telerik:RadButton ID="RadButton1" runat="server" Text="Get PanelItem" AutoPostBack="true"
    OnClick="RadButton1_Click">
</telerik:RadButton>

VB:
Public Shared dt As DataTable
Protected Sub Page_Load(sender As Object, e As EventArgs)
    RadPanelBar1.Items.Clear()
    Dim item1 As New RadPanelItem()
    item1.Text = "Temp"
    item1.Expanded = True
    item1.PreventCollapse = False
    item1.Selected = True
 
    dt = CreateTestTable()
    For Each row As DataRow In dt.Rows
        Dim txt As New TextBox()
        txt.ID = "txt" + row("Text").ToString()
        item1.Controls.Add(txt)
    Next
    RadPanelBar1.Items.Add(item1)
End Sub
Private Function CreateTestTable() As DataTable
    Dim table As New DataTable()
    table.Columns.Add("ID")
    table.Columns.Add("ParentID")
    table.Columns.Add("Text")
    table.Columns.Add("Tooltip")
    table.Rows.Add(New String() {"1", Nothing, "root1", "root 1 tooltip"})
    table.Rows.Add(New String() {"2", Nothing, "root2", "root 1 tooltip"})
    table.Rows.Add(New String() {"3", "1", "child1.1", "child 1.1 tooltip"})
    table.Rows.Add(New String() {"4", "1", "child1.2", "child 1.2 tooltip"})
    table.Rows.Add(New String() {"5", "1", "child1.3", "child 1.3 tooltip"})
    table.Rows.Add(New String() {"6", "5", "child1.3.1", "child 1.3.1 tooltip"})
    table.Rows.Add(New String() {"7", "5", "child1.3.2", "child 1.3.2 tooltip"})
    table.Rows.Add(New String() {"8", "5", "child1.3.3", "child 1.3.3 tooltip"})
    Return table
End Function
Protected Sub RadButton1_Click(sender As Object, e As EventArgs)
    For Each row As DataRow In dt.Rows
        Dim txt As TextBox = DirectCast(RadPanelBar1.Items(0).FindControl("txt" + row("Text").ToString()), TextBox)
    Next
End Sub

Thanks,
Shinu.
0
amni
Top achievements
Rank 1
answered on 20 Oct 2013, 11:08 AM
Hi Shinu,
thank you very much for your help.

It's work great,

I have a small question 4u.

after I add the controls, I wan't to change the text in textbox controls on button click.

if i do this, he don't do nothing

Dim
 txt As TextBox = DirectCast(RadPanelBar1.Items(0).FindControl("txt111"), TextBox)
txt.text = "text

where is my mistake?

thank you again, a lot.
0
Shinu
Top achievements
Rank 2
answered on 21 Oct 2013, 04:58 AM
Hi amni,

Unfortunately I couldn't replicate the issue at my end. Please provide your full code so that I can replicate the issue. I have noticed that the given code will cause an error, if we use 'Text' property instead of 'text ' for setting the text.

Thanks,
Shinu.

Tags
PanelBar
Asked by
amni
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
amni
Top achievements
Rank 1
Share this question
or