473,394 Members | 1,946 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Fill DataGrid

Hi,

How can I fill a datagrid without accessing to a database or any type of
file, only filling with a command button like this:
I have 3 textboxes that I must fill, and a button that when clicked pass
text of this 3 textboxes to my datagrid.

I want to manage (edit , update, etc) a datagrid but without accessing
DataBase. The unique interaction with that DB is a button that save all that
I have in datagrid into DB.

Hope you understand.

--
Programming ASP.NET with VB.NET
Thank's (if you try to help me)
Hope this help you (if I try to help you)
ruca
Nov 20 '05 #1
7 1544
Hi Ruca,

Please tell that you are using a WebDatagrid when you ask this in the
language.VB newsgroup.

I hope this was where you where looking for.

Cor
..
\\\
Dim ds As New DataSet
Dim dt As New DataTable("Ruca")
For i As Integer = 0 To 7
Dim dc As New DataColumn(Chr(i + 65))
dt.Columns.Add(dc)
Next
'And 12 rows every column filled with the same letter
For i As Integer = 0 To 11
dt.Rows.Add(dt.NewRow)
For y As Integer = 0 To dt.Columns.Count - 1
dt.Rows(i)(y) = Chr(i + 48)
Next
Next
ds.Tables.Add(dt)
datagrid1.datasource=dt.tables("Ruca")
datagrid1.databind
////

I hopethis helps?
Cor
Nov 20 '05 #2
And Can I update this datatable if I want? How?
--
Programming ASP.NET with VB.NET
Thank's (if you try to help me)
Hope this help you (if I try to help you)
ruca

"Cor Ligthert" <no**********@planet.nl> escreveu na mensagem
news:uQ****************@TK2MSFTNGP10.phx.gbl...
Hi Ruca,

Please tell that you are using a WebDatagrid when you ask this in the
language.VB newsgroup.

I hope this was where you where looking for.

Cor
.
\\\
Dim ds As New DataSet
Dim dt As New DataTable("Ruca")
For i As Integer = 0 To 7
Dim dc As New DataColumn(Chr(i + 65))
dt.Columns.Add(dc)
Next
'And 12 rows every column filled with the same letter
For i As Integer = 0 To 11
dt.Rows.Add(dt.NewRow)
For y As Integer = 0 To dt.Columns.Count - 1
dt.Rows(i)(y) = Chr(i + 48)
Next
Next
ds.Tables.Add(dt)
datagrid1.datasource=dt.tables("Ruca")
datagrid1.databind
////

I hopethis helps?
Cor

Nov 20 '05 #3
Hi Ruca,

You can put it in a session just by
session("ds") = ds

Updating a field can be something as (typed here watch typos)
\\\\
dim ds as new dataset = session("ds")
ds.tables(0).rows(index).item(fieldindex) = myvalue
///
or if you do a lot you can make it yourself more simple by
\\\
dim dr as datarow = ds.tables(0).rows(inded)
dr(fieldindex) = myvalue
///
I assume than you know the rest yourself?

If not feel free to ask again.

Cor
Nov 20 '05 #4
I have this:

Dim dt As DataTable
dt = Session.Item("myDt")

strCd = CStr(CType(E.Item.FindControl("edCod"), TextBox).Text)
dt.Rows(E.Item.ItemIndex).Item("Cod") = strCd

dgTeste.DataSource = dt
dgTeste.DataBind()

Session.Item("myDt") = dt

but it gives me an error saying: "Column 'Cod' is read only."
--
Programming ASP.NET with VB.NET
Thank's (if you try to help me)
Hope this help you (if I try to help you)
ruca
"Cor Ligthert" <no**********@planet.nl> escreveu na mensagem
news:uB**************@TK2MSFTNGP09.phx.gbl...
Hi Ruca,

You can put it in a session just by
session("ds") = ds

Updating a field can be something as (typed here watch typos)
\\\\
dim ds as new dataset = session("ds")
ds.tables(0).rows(index).item(fieldindex) = myvalue
///
or if you do a lot you can make it yourself more simple by
\\\
dim dr as datarow = ds.tables(0).rows(inded)
dr(fieldindex) = myvalue
///
I assume than you know the rest yourself?

If not feel free to ask again.

Cor

Nov 20 '05 #5
Hi Ruca,

I did not try it this way, however did you try it with a
Dim dt As New DataTable
dt = Session.Item("myDt")


Now you have set a reference to your Session item in my idea.

When it does not work give a message, than I check it deeper.

Cor
Nov 20 '05 #6
It gives me the same error.
"Cor Ligthert" <no**********@planet.nl> escreveu na mensagem
news:uy**************@TK2MSFTNGP09.phx.gbl...
Hi Ruca,

I did not try it this way, however did you try it with a
Dim dt As New DataTable
dt = Session.Item("myDt")


Now you have set a reference to your Session item in my idea.

When it does not work give a message, than I check it deeper.

Cor

Nov 20 '05 #7
Hi Ruca,

I was not able to do it completly dynamicly, however here a sample with what
I have strugled this morning. (And it works)

I hope it works for you as well?

Cor
\\\\In the HTML page in the datagrid
<Columns>
<asp:EditCommandColumn ButtonType="PushButton" UpdateText="Update"
CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
<asp:BoundColumn DataField="A"></asp:BoundColumn>
<asp:BoundColumn DataField="B"></asp:BoundColumn>
<asp:BoundColumn DataField="C"></asp:BoundColumn>
</Columns>
///
\\\
Dim dt As New DataTable("Ruca")
Private Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
For i As Integer = 0 To 2
Dim dc As New DataColumn(Chr(i + 65))
dt.Columns.Add(dc)
Next
For i As Integer = 0 To 9
dt.Rows.Add(dt.NewRow)
For y As Integer = 0 To dt.Columns.Count - 1
dt.Rows(i)(y) = Chr(i + 48)
Next
Next
DataGrid1.DataSource = dt
DataGrid1.DataKeyField = dt.Columns(0).ColumnName
DirectCast(DataGrid1.Columns(1), BoundColumn).ReadOnly = True
DataGrid1.DataBind()
Session.Item("dt") = dt
Else
dt = DirectCast(Session.Item("dt"), DataTable)
DataGrid1.DataSource = dt
DirectCast(DataGrid1.Columns(1), BoundColumn).ReadOnly = True
DataGrid1.DataKeyField = dt.Columns(0).ColumnName
End If
End Sub
Private Sub DataGrid1_CancelCommand1(ByVal source _
As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) _
Handles DataGrid1.CancelCommand
DataGrid1.EditItemIndex = -1
DataGrid1.DataBind()
End Sub
Private Sub DataGrid1_EditCommand1(ByVal source As Object, _
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) _
Handles DataGrid1.EditCommand
DataGrid1.EditItemIndex = e.Item.ItemIndex
DataGrid1.DataBind()
End Sub

Private Sub DataGrid1_UpdateCommand(ByVal source As Object, _
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) _
Handles DataGrid1.UpdateCommand
Dim dv As New DataView(dt)
dv.RowFilter = dt.Columns(0).ColumnName & "=" _
& DataGrid1.DataKeys(e.Item.ItemIndex).ToString()
dv(0)(1) = DirectCast(e.Item.Cells(2).Controls(0), TextBox).Text()
dv(0)(2) = DirectCast(e.Item.Cells(3).Controls(0), TextBox).Text
Session.Item("dt") = dt
End Sub
End Class
///
Nov 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bil Muh | last post by:
Hello Developers, I would like to fill a data grid on my "Windows Forms (.NET)" by a background thread. I read some data from a binary file. With the information read from this file, I create...
7
by: ruca | last post by:
Hi, How can I fill a datagrid without accessing to a database or any type of file, only filling with a command button like this: I have 3 textboxes that I must fill, and a button that when...
6
by: JeffB | last post by:
I have tried several different methods of getting a datagrid to fill with information. Below is the code I'm now using. When viewed in the browser and the text box filled with a parameter value...
4
by: Dave Edwards | last post by:
I understand that I can fill a datagrid with multiple queries, but I cannot figure out how to fill a dataset with the same query but run against multiple SQL servers, the query , table structure...
4
by: jaYPee | last post by:
I have already done some code to fill the datagrid. my problem is that the fill method is too slow after executing my code. here is the scenario. i have a parent/child form. all is datagrid....
4
by: jaYPee | last post by:
I have 1 dataset called "dataset1" that contains 2 tables called "course" and "courseload". in my form i have a datagrid. the datasource of this datagrid is "dataset1" and the datamember is...
2
by: Brett | last post by:
I have the following code in VS Studio .NET 2005 beta: Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.DataAdapter1.Fill(DataSet1) ...
1
by: Mrozu | last post by:
Hi I need execute SELECT SQL query in DataSet. No in SQL server(da.selectcommand) and fill dataset, only show in datagrid filtered by select-where query records from dataset:) For example I...
2
by: MDB | last post by:
Hello All, I have a data grid that I fill using a dataset. The results of the query has around 15 columns and 500 rows (and growing). The reason I am using the datagrid is so the end users can...
3
by: Rushi Panchal | last post by:
Hiii I have a one textbox ,one button,one datagridm i want to fill datagrid anything type in textbox and press button than whatever value in text box is going to datagrid and so on and i don't use...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.