none
How does data binding work? RRS feed

  • Question

  • I am curious how the data binding process is able to identify the column and row data.

    My data is:

      string[,] list = new string[,]{{"Name","Peter"},{"Phone","1234567"}};
    
    

    When I bind this to a DetailsView (System.Web.UI.WebControls.DetailsView):

      DetailsView1.DataSource = list;
      DetailsView1.DataBind();
    
    

    All I get is:

    Item Name

    What can I do to make it show Name | Peter on the first row and Phone | 1234567 on the second?

    Thanks.

    • Moved by VMazur Wednesday, July 14, 2010 10:24 AM (From:ADO.NET Managed Providers)
    Wednesday, July 14, 2010 6:04 AM

Answers

  • Hello,

     

    Welcome to ADO.NET Managed Providers forum!

     

    I am not an expert of ASP.NET databinding, but based on my understanding, the data binding process searches the public properties of the data classes.   Besides, DetailsView seems to only display a single record’s value, http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.detailsview.aspx.    So to meet your request, I created some sample codes like:

    ==================================================================================

                List<MyItem> list = new List<MyItem>() { new MyItem { Name = "Peter", Phone = "1234567" } };

                DetailsView1.DataSource = list;

                DetailsView1.DataBind();

     

            public class MyItem

            {

                public string Name { get; set; }

                public string Phone { get; set; }

            }

    ==================================================================================

     

    Additional references about ASP.NET databinding, http://support.microsoft.com/kb/307860/en-us. 

     

    Also, I would recommend you consult the ASP.NET databinding issues at the ASP.NET Data Access forums here, http://forums.asp.net/default.aspx/16.  

     

    Good day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by K.Kong Thursday, July 15, 2010 7:28 AM
    Wednesday, July 14, 2010 8:50 AM

All replies

  • Hello,

     

    Welcome to ADO.NET Managed Providers forum!

     

    I am not an expert of ASP.NET databinding, but based on my understanding, the data binding process searches the public properties of the data classes.   Besides, DetailsView seems to only display a single record’s value, http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.detailsview.aspx.    So to meet your request, I created some sample codes like:

    ==================================================================================

                List<MyItem> list = new List<MyItem>() { new MyItem { Name = "Peter", Phone = "1234567" } };

                DetailsView1.DataSource = list;

                DetailsView1.DataBind();

     

            public class MyItem

            {

                public string Name { get; set; }

                public string Phone { get; set; }

            }

    ==================================================================================

     

    Additional references about ASP.NET databinding, http://support.microsoft.com/kb/307860/en-us. 

     

    Also, I would recommend you consult the ASP.NET databinding issues at the ASP.NET Data Access forums here, http://forums.asp.net/default.aspx/16.  

     

    Good day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by K.Kong Thursday, July 15, 2010 7:28 AM
    Wednesday, July 14, 2010 8:50 AM
  • Thanks.  This works. 

    I am still curious why a single record wouldn't work for DetailsView.  Why do you have to use a List of one element? 

    For a GridView I can understand.

    Thursday, July 15, 2010 7:30 AM
  • You’re welcome! 

     

    For the detailed databinding logic for the DetailView control, I would recommend you consult it at the ASP.NET forum here, http://forums.asp.net/default.aspx/16.

     

    Have a nice weekend!

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Friday, July 16, 2010 9:10 AM