Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Fill DataGrid

Reply
Thread Tools

Fill DataGrid

 
 
ruca
Guest
Posts: n/a
 
      05-19-2004
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


 
Reply With Quote
 
 
 
 
Cor Ligthert
Guest
Posts: n/a
 
      05-19-2004
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 + 4
Next
Next
ds.Tables.Add(dt)
datagrid1.datasource=dt.tables("Ruca")
datagrid1.databind
////

I hopethis helps?
Cor


 
Reply With Quote
 
 
 
 
ruca
Guest
Posts: n/a
 
      05-19-2004
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" <(E-Mail Removed)> escreveu na mensagem
news:uQn%(E-Mail Removed)...
> 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 + 4
> Next
> Next
> ds.Tables.Add(dt)
> datagrid1.datasource=dt.tables("Ruca")
> datagrid1.databind
> ////
>
> I hopethis helps?
> Cor
>
>



 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      05-19-2004
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


 
Reply With Quote
 
ruca
Guest
Posts: n/a
 
      05-19-2004
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" <(E-Mail Removed)> escreveu na mensagem
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      05-19-2004
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


 
Reply With Quote
 
ruca
Guest
Posts: n/a
 
      05-19-2004
It gives me the same error.


"Cor Ligthert" <(E-Mail Removed)> escreveu na mensagem
news:uyJ$(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      05-20-2004
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 + 4
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
///


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How fill the URL field in DataGrid 4 abc.aspx?key=xyz 4 each recor =?Utf-8?B?ZGF2aWQ=?= ASP .Net 4 10-18-2005 10:58 PM
Datagrid embedded textbox text fill on postback Peppie ASP .Net 0 06-01-2005 06:59 PM
Datagrid fails to fill =?Utf-8?B?SmVmZkI=?= ASP .Net 6 01-13-2005 10:53 PM
Please help!!! Need datagrid selection to fill textboxes...Need quick!! TN Bella ASP .Net 1 06-18-2004 01:31 AM
Looking for a quicker way to fill a datagrid??? Helixpoint ASP .Net 4 08-01-2003 10:42 AM



Advertisments