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

Loading panelbar texboxes with data from SQL Query in code behind

1 Answer 91 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Joe
Top achievements
Rank 2
Joe asked on 23 May 2010, 07:49 AM
I've been trying to solve this problem for about 12 hours now...

I have a panelbar with multiple sections. On Page Load (or when the user switches to a different panel section) I want to populate that section textboxs with the appropriate information from the SQL query in Code Behind (or anywhere else that will work in each section).

For example:

Panel 1 - Login Information
---- Login:         asp textbox ID: txtLogin
---- Password:  asp textbox ID: txtPassword1
---- Confirm Password: asp textbox ID: txtPassword1
---- "Save Button"

When clicking the save button I want to save the section data back to the database and do a postback to the same section.

In code behind doing a simple query to member data base using Member_ID as filter.
For example: (sudo code)
Session("MemberID") = "760"
Select Member_ID, mem_login, mem_pass from Personal_Info Where Member_ID = Session("MemberID")

The query returns:
mem_login: jadam
mem_pass: xxxxx

Here's the code behind:

 Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load  
 
        'Get User login information from database  
          
        Dim ConnectionString As String = ConfigurationManager.ConnectionStrings("AcvpmDataCS").ConnectionString  
        Dim conn As New SqlConnection(ConnectionString)  
        Dim cmd As New SqlCommand("Select Member_ID, mem_login, mem_password FROM Personal_Info WHERE Member_ID = @member_id", conn)  
          
        Using conn  
            conn.Open()  
            cmd.Parameters.AddWithValue("@member_id", Session("MemberID"))  
 
            Dim Reader As SqlDataReader = cmd.ExecuteReader  
            While Reader.Read()  
                Dim txtLogin As TextBox = CType(RadPanelBar1.FindControl("txtLogin"), TextBox)  
                txtLogin.Text = Reader("mem_login").ToString  
 
            End While 
            conn.Close()  
        End Using  
 
    End Sub 


I've tested the query (used it in other places) and the query returns the proper information I just don't know how to map the panelbar items to the SQL Select results.

I want to have a "Save" button in each panel section since there is a lot of information on each user (over 360 fields) spread out through multiple sections of the PanelBar. 

Panel 2 - Home Address
Same setup as login with labels and textboxes of their address information

Panel 3 - Busines Address
etc.

Any suggestions?
Thanks,
Joe

1 Answer, 1 is accepted

Sort by
0
Nikolay Tsenkov
Telerik team
answered on 24 May 2010, 05:20 PM
Hello Joe,

This code breaks on the line:
txtLogin.Text = Reader("mem_login").ToString

,  because on the previous one:
Copy Code
Dim txtLogin As TextBox = CType(RadPanelBar1.FindControl("txtLogin"), TextBox)
the txtLogin is not being set. And this is caused by the fact that you are trying to access it with FindControl directly on the RadPanelBar object and this cannot be achieved if the control is in a template. You have to use FindControl, but directly on the actual item which txtLogin you want to find.

Here is a nice article that should give you a better idea of interacting with controls in template:http://www.telerik.com/help/aspnet-ajax/panel_templatesaccessingcontrols.html

Hope this is going to help!

Regards,
Nikolay Tsenkov
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
PanelBar
Asked by
Joe
Top achievements
Rank 2
Answers by
Nikolay Tsenkov
Telerik team
Share this question
or