Fill DataGrid

Discussion in 'ASP .Net' started by ruca, May 19, 2004.

  1. ruca

    ruca Guest

    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
    ruca, May 19, 2004
    #1
    1. Advertising

  2. ruca

    Cor Ligthert Guest

    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
    Cor Ligthert, May 19, 2004
    #2
    1. Advertising

  3. ruca

    ruca Guest

    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" <> escreveu na mensagem
    news:uQn%...
    > 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
    >
    >
    ruca, May 19, 2004
    #3
  4. ruca

    Cor Ligthert Guest

    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
    Cor Ligthert, May 19, 2004
    #4
  5. ruca

    ruca Guest

    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" <> escreveu na mensagem
    news:...
    > 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
    >
    >
    ruca, May 19, 2004
    #5
  6. ruca

    Cor Ligthert Guest

    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
    Cor Ligthert, May 19, 2004
    #6
  7. ruca

    ruca Guest

    It gives me the same error.


    "Cor Ligthert" <> escreveu na mensagem
    news:uyJ$...
    > 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
    >
    >
    ruca, May 19, 2004
    #7
  8. ruca

    Cor Ligthert Guest

    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
    ///
    Cor Ligthert, May 20, 2004
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Helixpoint
    Replies:
    4
    Views:
    411
    John Saunders
    Aug 1, 2003
  2. TN Bella
    Replies:
    1
    Views:
    2,471
    Edward
    Jun 18, 2004
  3. =?Utf-8?B?SmVmZkI=?=

    Datagrid fails to fill

    =?Utf-8?B?SmVmZkI=?=, Jan 13, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    379
    =?Utf-8?B?dmluYXk=?=
    Jan 13, 2005
  4. Peppie
    Replies:
    0
    Views:
    805
    Peppie
    Jun 1, 2005
  5. =?Utf-8?B?ZGF2aWQ=?=
    Replies:
    4
    Views:
    2,135
    =?Utf-8?B?RWx0b24gVw==?=
    Oct 18, 2005
Loading...

Share This Page