CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2002
    Location
    Alpharetta, GA
    Posts
    51

    datagrid databind implementation

    I was wondering if anyone could shed some light on exactly how the datagrid binds to a datatable.

    I know for instance that the datagrid will bind to public properties of an object (and not public fields for some reason). And I know that ITypedList plays some role when a datagrid binds to a table. But how does the datagrid know how to extract the field values from a tablerow??

    I've tried using indexers in my own objects to facilitate a binding but the datagrid seems to ignore it.

    Is there some other interface that the datatable is implementing which allows the datagrid to retrieve its fields by name?

    I can't seem to find anything about it on msdn. Any help would be greatly appreciated!

  2. #2
    Join Date
    Nov 2002
    Location
    Seoul
    Posts
    13
    Hi,
    Pls see this and it will explain :
    'Binding data source to datagrid
    DataGrid1.DataSource = ds
    DataGrid1.DataMember = "Users"
    DataGrid1.DataBind()
    You have to cast the item in tablerows into TextBox like this inorder to access to it's value:

    Dim unameText As TextBox = CType(e.Item.Cells(1).Controls(0), TextBox)
    Dim uidText As TextBox = CType(e.Item.Cells(0).Controls(0), TextBox)
    Dim dateText As TextBox = CType(e.Item.Cells(2).Controls(0), TextBox)
    Dim empnumText As TextBox = CType(e.Item.Cells(3).Controls(0), TextBox)
    Dim upassText As TextBox = CType(e.Item.Cells(4).Controls(0), TextBox)

    par1 = uidText.Text
    par2 = unameText.Text
    par3 = dateText.Text
    par4 = empnumText.Text
    par5 = upassText.Text


    Hope this help,
    rgds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured