How do I connect the textbox with data from DB

4 posts, 1 answers
  1. clo
    clo avatar
    9 posts
    Member since:
    Aug 2011

    Posted 01 Sep 2011 Link to this post

    My problem is how do I connect  the TextBox within the RadListView whit the connection that I created so that they could display data from the table. I know that I use ... but then I do not know how ... someone can help me? I attach the key file with one of my experiments!

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.Adapters;
    using Oracle.DataAccess.Client;
    using Telerik.OpenAccess.Config.Sql;
    using System.Data;
    using Telerik.Web.UI;

    namespace WebApplication1
    {
        //ccc i due pezzi commentati in questo caso non servono



        public partial class WebForm1 : System.Web.UI.Page
        {
            private OracleConnection conn = new OracleConnection(); //ccc creo una nuova istanza OracleConnection
            private OracleCommand cmd;  //ccc creo una nuova istanza OracleCommand
            private OracleDataReader dr;
            private OracleDataAdapter da;
            private OracleCommandBuilder cb;
            private DataSet ds;

            string sql = " select tasso_iva, max(data_inizio), data_fine from tassi_iva";   //dichiaro una variabile e le associo la query
            //+ "where data_inizio = to_date('01.01.01', 'DD.MM.YY')";

            
            protected void Page_Load(object sender, EventArgs e)
            {
                string ConnString = "data source=OG_DB2;password=ghid101;user id=OG_GHIDONI";

                conn.ConnectionString = ConnString; //ccc associo la connection string con un connection object

                

                try
                {
                    conn.Open();    //ccc apro la connessione                                   

                    
                    OracleCommand cmd = new OracleCommand(sql, conn); // ccc creo un oggetto di tipo Oracle Command

                    cmd.CommandType = CommandType.Text;

                    /*da = new OracleDataAdapter(cmd);
                    cb = new OracleCommandBuilder(da);
                    ds = new DataSet();

                    da.Fill(ds);*/

                    //RgIva.DataSource = ds.Tables[0];

                    OracleDataReader dr = cmd.ExecuteReader();  // ccc creo un oggetto ORacleDataReader e gli associo il metodo ripreso dalla
                                                                //ccc classe OracleCommand

                    while (dr.Read())
                    {

                        /*tb_iva.Text = dr["tasso_iva"].ToString();
                        rdp_inizio.SelectedDate = Convert.ToDateTime(dr["data_inizio"]);
                        rdp_fine.SelectedDate = Convert.ToDateTime(dr["data_fine"]);*/
                    }


                }

                catch (Exception ex) // ccc catches any error
                {
                    MessageBox.Show(ex.Message.ToString());
                }

                conn.Close();
            }

            protected void RadListView1_ItemCreated(object sender, RadListViewItemEventArgs e)
            {

                if (e.Item is RadListViewDataItem)
                {
                    TextBox tb_iva = e.Item.FindControl("TbIVA") as TextBox;
                    RadDatePicker rdp_inizio = e.Item.FindControl("RdpInizio") as RadDatePicker;
                    RadDatePicker rdp_fine = e.Item.FindControl("RdpFine") as RadDatePicker;

                    tb_iva.Text = dr["tasso_iva"].ToString();
                    rdp_inizio.SelectedDate = Convert.ToDateTime(dr["data_inizio"]);
                    rdp_fine.SelectedDate = Convert.ToDateTime(dr["data_fine"]);

                }
            }

            private OracleDataReader ReadRecords(string query)
            {
                conn.Open();    //ccc apro la connessione                                   

                OracleCommand cmd = new OracleCommand(sql, conn); // ccc creo un oggetto di tipo Oracle Command

                cmd.CommandType = CommandType.Text;

                OracleDataReader dr = cmd.ExecuteReader();

                return dr;
            }

            protected void RadListView1_NeedDataSource(object source, Telerik.Web.UI.RadListViewNeedDataSourceEventArgs e)
            {
                RadListView1.DataSource = ReadRecords(sql);
            }

            protected void RadListView1_DataBound(object sender, System.EventArgs e)
            {
                dr.Close();
            }

        }
    }
    Thanks a lot
    Clo
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 01 Sep 2011 Link to this post

    Hello Clo,

    Please take a look into the following help document which explains how to bind controls in RadListview.
    Simple versus Advanced Binding.

    Thanks,
    Princy.
  3. clo
    clo avatar
    9 posts
    Member since:
    Aug 2011

    Posted 01 Sep 2011 Link to this post

    Ok thanks now I will look!
  4. clo
    clo avatar
    9 posts
    Member since:
    Aug 2011

    Posted 02 Sep 2011 Link to this post

    Excuse me now I have an other problem...this



    I'm trying to understand, but maiby why I am at begin whit all this things ...I can not reach!
    thanks for help
Back to Top