Bind Data To RadGridView

13 posts, 0 answers
  1. Hengky
    Hengky avatar
    60 posts
    Member since:
    Sep 2015

    Posted 07 Jan 2016 Link to this post

    Hello All, 

    I have the problem with RadGridView.

    How to fill RadGridView with only selected field from dataset.

    I have 4 field in dataset, and only field BERAT that only i want to fill to datagrid.

    How can make this happen.

     

    The field is : NoTransaksi, NoUrut, Berat

     

     

     

  2. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3896 posts

    Posted 07 Jan 2016 Link to this post

    Hello Hengky,

    Thank you for writing.

    You can refer to the following stackOverflow threads demonstrating how to fill a DataTable from query selecting the specific columns:
    http://stackoverflow.com/questions/11993211/how-to-fill-datatable-with-sql-table
    http://stackoverflow.com/questions/16958155/fill-datatable-from-sql-server-database
    http://stackoverflow.com/questions/12947872/quickest-way-to-create-datatable-from-query
    Afterwards, you can set the DataTable as RadGridView.DataSource.

    An alternative solution is to hide the undesired columns by setting the IsVisible property to false of the specific column.

    I hope this information helps. Should you have further questions I would be glad to help.
     
    Regards,
    Dess
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  3. Hengky
    Hengky avatar
    60 posts
    Member since:
    Sep 2015

    Posted 07 Jan 2016 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Hello Dess 

    Thanks for reply... for the solution you gave to me. I have did it but the problem is 

    the grid can be to input and show the data. 

    it can be done with add the data manually. with for looping. but i want to know if there another way to fill the data from dataset.

    so i just bind the column to dataset.

     (hope you understand with what i mean) 

     

    thanks before

  4. Hengky
    Hengky avatar
    60 posts
    Member since:
    Sep 2015

    Posted 08 Jan 2016 Link to this post

    Hello Dess 

    Or how to bind the field direct to the column 

     Thanks

  5. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3896 posts

    Posted 08 Jan 2016 Link to this post

    Hello Hengky,

    Thank you for writing back. 

    If you have filled the DataTable successfully, you can use it as DataSource for RadGridView. You can find additional information in the GridView >> Populating with Data section in the online documentation.

    As to the question about binding the field directly to the column when the column is added programmatically, it is necessary to specify the FieldName property of the column. A sample code is available here: http://www.telerik.com/help/winforms/gridview-columns-gridviewtextboxcolumn.html

    I hope this information helps. If you have any additional questions, please let me know.

    Regards,
    Dess
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  6. Hengky
    Hengky avatar
    60 posts
    Member since:
    Sep 2015

    Posted 10 Jan 2016 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Hello Dess

    This what i do manual for fill the data to gridview 

            Me.GridManual.Rows.Clear()
            cmd = New SqlCommand("SELECT * FROM TrManualDtl WHERE NoTransaksi='" & LblNoTransaksi.Text & "' ORDER BY NoUrut", conn)
            rd = cmd.ExecuteReader
            While rd.Read()
                Me.GridManual.Rows.Add(rd("Berat").ToString)
            End While
            rd.Close()

     how to bind direct from dataadapter or datareader this code what i tried ... but not solved my problem

            'da = New SqlDataAdapter("Select * from TrManualDtl Where NoTransaksi='" & GridListManual.Rows(i).Cells(0).Value.ToString() & "' ORDER BY NoUrut", conn)
            'ds = New DataSet
            'ds.Clear()
            'da.Fill(ds, "TrManualDtl")
            'GridManual.Columns(0).FieldName = "Berat"
            ''GridManual.DataSource = (ds.Tables("TrManualDtl")) 

     thanks

  7. Hristo
    Admin
    Hristo avatar
    1519 posts

    Posted 13 Jan 2016 Link to this post

    Hi Hengky,

    Thank you for writing back.

    I am sending you attached a project demonstrating how you can load data in RadGridView using a DataReader object. The example includes two grids using the same data, the first one has auto-generated columns while the second one uses columns defined at design-time. The columns of the second grid are mapped to the data object via their FieldName property as my colleague explained earlier.

    Additional information is available here: 

    I am also attaching a short animation showing the result on my end.

    I hope this helps. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  8. jehad
    jehad avatar
    3 posts
    Member since:
    Nov 2016

    Posted 18 Feb in reply to Hristo Link to this post

    Dear Hristo,

    In your project, the grid display all columns not only column1 and column2.

    Please see attachment picture.

    Thanks.

  9. Hengky
    Hengky avatar
    60 posts
    Member since:
    Sep 2015

    Posted 18 Feb in reply to jehad Link to this post

    Hello Jehad trying to help ... 

    It's because u set the column diffrent with your's table ... 

    please check the table in your's query ... 

  10. jehad
    jehad avatar
    3 posts
    Member since:
    Nov 2016

    Posted 19 Feb in reply to Hengky Link to this post

    Hi Hengky,

    Everything is right, the table and the query, you can try the attached project in Hristos' post.

    It's repeating the columns.

    Thanks

  11. Hengky
    Hengky avatar
    60 posts
    Member since:
    Sep 2015

    Posted 19 Feb in reply to jehad Link to this post

    Hi Jehad ... i have tried it a long time ago and it's working fine .. 

     

  12. jehad
    jehad avatar
    3 posts
    Member since:
    Nov 2016

    Posted 20 Feb in reply to Hengky Link to this post

    Hi Hengky,

    Please see the attached picture. This screen for same project without change anything in the code.

    only change some designer code because of the version like:

    this.radGridView2.MasterTemplate.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;

    to

    this.radGridView2.MasterGridViewTemplate.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;

    and 

    gridViewTextBoxColumn1.Name = "column1";

    to

    gridViewTextBoxColumn1.UniqueName = "column1";

    Thanks

  13. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3896 posts

    Posted 21 Feb Link to this post

    Hello, Jehad, 

    I have downloaded the project provided by Hristo on 13 Jan 2016. Please refer to the attached gif file illustrating the behavior on my end with the latest version.

    The three added columns remain in the right grid control. As to the specified changes, I would like to note that GridViewTextBoxColumn doesn't offer a UniqueName property. 

    Could you please specify what are the exact changes that you made in the code or at design time in the prject which results in the multiple columns displayed on your end with Hristo's project?

    I am looking forward to your reply.

     

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top