Thursday, March 29, 2012

manualy filled unbound grid

I need a sample code on unbound grid mannualy filled with data in VB.net or ASpHi,

Can you post more info about your requirement?
It is time sheet application.
Grid suppose to retrieve my data (weeekly time sheet) from ds, but not to be bound to it since user might need to edit his time sheets, moreover grid will have more columns than data set. For example time stamps from dataset will be transfer to week days in grid and hours should be allocated accordingly to the day of the week. After user is done billing his time, I think I have to create a data set from the grid and send it to data base for future update.

F.e.
----------------------------
ProjectNo ProjectName Description Mon Tuesday Wen Thir
-------------------------------
0001 Domtar solution initial meetings 2 3.5

It is my fist project in .net and I am quite lost.
Thank you for your help
Hi,

Try as below :


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DataGridTimeSheet.DataSource = CreateDataSource()
DataGridTimeSheet.DataBind()
End Sub

Function CreateDataSource() As ICollection
Dim dt As DataTable
Dim dr As DataRow
Dim i As Integer
Dim NbrOfRowsRequired As Integer
NbrOfRowsRequired = 10

dt = New DataTable
dt.Columns.Add(New DataColumn("RowId", GetType(Integer)))
dt.Columns.Add(New DataColumn("ProjectNo", GetType(String)))
dt.Columns.Add(New DataColumn("ProjectName", GetType(String)))
dt.Columns.Add(New DataColumn("Description", GetType(String)))
dt.Columns.Add(New DataColumn("Mon", GetType(String)))
dt.Columns.Add(New DataColumn("Tue", GetType(String)))
dt.Columns.Add(New DataColumn("Wed", GetType(String)))

For i = 1 To NbrOfRowsRequired
dr = dt.NewRow()
dr(0) = i
dr(1) = "00" + i.ToString() 'Assign your data from database here
dr(2) = "Your Project Name : " + i.ToString() 'Assign your data from database here
dr(3) = "Your Desc : " + i.ToString() 'Assign your data from database here
dr(4) = "0"
dr(5) = "0"
dr(6) = "0"
dt.Rows.Add(dr)
Next
CreateDataSource = New DataView(dt)
End Function

HTH
Thank you very much!
Hello

May I ask you how it would be possible to add rows for an existing datagrid?
I think the command 'dt = New DataTable' should be replaced with the name of the datagrid somehow.

In advance thank you very much for your answer.

Rene

0 comments:

Post a Comment