I want to populate a GridView without using a DataSource. I want to created a Protected Sub that will take information I have calculated and display it on multiple rows (5 to be specific). Can this be done easly?
' Add rows with those columns filled in the DataTable.
for example
table.Rows.Add(25, "Indocin", "David", DateTime.Now)
table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now)
Return table
End Function
End Module
then bind the table to the Gridview
GridView1.DataSource= dt GridView1.DataBind()
BSCS-MCTS-MCP-MS
Mark As Answer if my reply helped you
Pray|Game|Code - My Way of Living
' Add rows with those columns filled in the DataTable.
for example
table.Rows.Add(25, "Indocin", "David", DateTime.Now)
table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now)
Return table
End Function
End Module
then bind the table to the Gridview
GridView1.DataSource = dt GridView1.DataBind()
I'm confused on the Binding part. Where is dt coming from?
Member
17 Points
146 Posts
Populate GridView without DataSource
Jul 16, 2012 08:37 AM|maddtechwf|LINK
I want to populate a GridView without using a DataSource. I want to created a Protected Sub that will take information I have calculated and display it on multiple rows (5 to be specific). Can this be done easly?
Member
507 Points
267 Posts
Re: Populate GridView without DataSource
Jul 16, 2012 08:43 AM|Keyur Shah|LINK
It means you want to fill grid using through code not directly throug DataSource?? Right?
Member
163 Points
195 Posts
Re: Populate GridView without DataSource
Jul 16, 2012 08:43 AM|swaiss|LINK
you can put your results in a DataTable then make the data source your DataTable.
hope this helps you.
regards.
Member
507 Points
267 Posts
Re: Populate GridView without DataSource
Jul 16, 2012 08:45 AM|Keyur Shah|LINK
Member
281 Points
95 Posts
Re: Populate GridView without DataSource
Jul 16, 2012 08:51 AM|EhsanMubeen|LINK
Module Module1 Sub Main() ' Get a DataTable instance from helper function. Dim table As DataTable = GetTable() End Sub
Mark As Answer if my reply helped you
Pray|Game|Code - My Way of Living
Member
17 Points
146 Posts
Re: Populate GridView without DataSource
Jul 16, 2012 09:50 AM|maddtechwf|LINK
I'm a little confused on how to implement this.
I tried the above code but I was not able to reference any of my Protected Sub's to populate some of the rows.
Member
163 Points
195 Posts
Re: Populate GridView without DataSource
Jul 16, 2012 10:59 AM|swaiss|LINK
please refer these links
http://www.dotnetperls.com/datatable-vbnet
http://www.dotnetperls.com/datatable
http://www.dotnetperls.com/convert-list-datatable
Member
17 Points
146 Posts
Re: Populate GridView without DataSource
Jul 16, 2012 11:41 AM|maddtechwf|LINK
I'm confused on the Binding part. Where is dt coming from?
Member
281 Points
95 Posts
Re: Populate GridView without DataSource
Jul 16, 2012 01:30 PM|EhsanMubeen|LINK
Actually the line of code should be
Gridview1.Datasource = table; // table which you are declarating on Main
Gridview1.databind();
My bad
Mark As Answer if my reply helped you
Pray|Game|Code - My Way of Living
Member
17 Points
146 Posts
Re: Populate GridView without DataSource
Jul 17, 2012 01:35 PM|maddtechwf|LINK
When I have the code you provided in the Module Module 1, I can't access any of my other functions in my Partial Class _Default. Any suggestions?
Member
17 Points
146 Posts
Re: Populate GridView without DataSource
Jul 17, 2012 05:46 PM|maddtechwf|LINK
Had to add this line of code to fix it not showing up.