RE: bind datagrid to dataset filled at runtime

Discussion in 'ASP .Net' started by =?Utf-8?B?QmluIFNvbmcsIE1DUA==?=, Apr 8, 2004.

  1. Hi, Amy

    Where do you define the dataset "ds_new"
    I would expect that in the beginning of your page as
    Public ds_new as datase
    However, this varible will not be preserved between posting back.
    The solution is in page_load event add
    If Not ViewState("ds_new") is nothing Then ds_new = Ctype(ViewState("ds_new"), Dataset
    And in page_prerender event ad
    ViewState("ds_new") = ds_ne

    Bin Song, MC


    ----- amy wrote: ----

    on an asp.net page I have a datagrid I want to databiind to a dataset that I fill at runtime with data input via textboxes in the footer of the datagrid. The item command "add" works and the datagrid displays the new record. The problem is that it only displays the last record added. I have tried using a dataview which still doesn't work. I can do this the old fashioned way but wnt to use this method so that I can update 2 database tables at the same time. Below is the code ... any help is greatly appreciated

    Sub dg_Details_Add_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dg_Details_Add.ItemComman
    If e.CommandName = "Insert" The
    Dim txtdesc As TextBo
    Dim txtqty As TextBo
    Dim txtcost As TextBo
    Dim strdesc As Strin
    Dim intqty As Intege
    Dim deccost As Decima

    txtdesc = e.Item.FindControl("txt_add_desc"
    strdesc = txtdesc.Tex

    txtqty = e.Item.FindControl("txt_add_qty"
    If txtqty.Text = "" The
    intqty =
    Els
    intqty = CType(txtqty.Text, Integer
    End I


    txtcost = e.Item.FindControl("txt_add_cost"
    If txtcost.Text = "" The
    deccost = 0.
    Els
    deccost = CType(txtcost.Text, Decimal

    End I

    Dim mydatarow As DataRo
    mydatarow = ds_new.Tables("mytable").NewRo
    mydatarow("Description") = strdes
    mydatarow("qty") = intqt
    mydatarow("cost") = deccos
    ds_new.Tables("myTable").Rows.Add(mydatarow
    ds_new.AcceptChanges(
    ds_new.GetChanges(
    dg_Details_Add.DataBind(
    End I
    End Sub
    =?Utf-8?B?QmluIFNvbmcsIE1DUA==?=, Apr 8, 2004
    #1
    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. AFN
    Replies:
    3
    Views:
    3,221
    Kevin Spencer
    Feb 16, 2004
  2. Bennett Haselton
    Replies:
    2
    Views:
    14,274
    Bennett Haselton
    Oct 7, 2004
  3. =?Utf-8?B?SklNLkgu?=

    Q: dataset not filled in

    =?Utf-8?B?SklNLkgu?=, Apr 5, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    644
    Scott Allen
    Apr 5, 2005
  4. Yasin cepeci
    Replies:
    0
    Views:
    298
    Yasin cepeci
    Jun 4, 2007
  5. Yasin cepeci
    Replies:
    1
    Views:
    298
    Alexey Smirnov
    Jun 4, 2007
Loading...

Share This Page