Urgent.. prob w/ Datagrid edit button

Discussion in 'ASP .Net' started by slinky, Oct 6, 2008.

  1. slinky

    slinky Guest

    I had a successfully deployed datagrid reading an XML file and
    showing the data:

    Private Function MakeDataView() as DataView
    Dim myDataSet As New DataSet()
    myDataSet.ReadXml(Server.MapPath("TimberSales.xml"))
    Dim view As DataView = New DataView(myDataSet.Tables(0))
    view.AllowDelete = False
    view.AllowEdit = True
    view.AllowNew = False
    view.Sort = "Year ASC"
    Return view
    End Function


    Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    Dim view as DataView = MakeDataView()
    dgTimber.DataSource = view
    dgTimber.AllowSorting = True
    dgTimber.DataBind()
    End Sub
    ______________________________________________________________________


    I wanted to add an "Edit" button as desribed at:
    http://msdn.microsoft.com/en-us/library/aa984288(VS.71).aspx:


    Private Sub dgTimber_EditCommand(ByVal source As Object, _
    ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) _
    Handles dgTimber.EditCommand
    dgTimber.EditItemIndex = e.Item.ItemIndex
    dgTimber.DataBind()
    End Sub


    Dim newData As String
    Dim aTextBox As TextBox
    aTextBox = CType(e.Item.Cells(1).Controls(0), TextBox)
    **** says "aTextBox" is not declared, (?)
    newData =
    aTextBox.Text **** says
    "newData" is not declared, (?)


    Private Sub dgTimber_UpdateCommand(ByVal source As Object, _
    ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) _
    Handles dgTimber.UpdateCommand
    Dim quantityCell As TableCell = e.Item.Cells(6)
    Dim quantityBox As TextBox = _
    CType(quantityCell.Controls(0), TextBox)
    Dim quantity As Integer =
    System.Int32.Parse(quantityBox.Text)
    dgTimber.EditItemIndex = -1
    dgTimber.DataBind()
    End Sub


    When I hit the Edit Button I get this:


    Invalid postback or callback argument. Event validation is
    enabled
    using <pages enableEventValidation="true"/>
    in configuration or <%@ Page EnableEventValidation="true" %> in a
    page. For security purposes, this feature ....etc.


    Does anything obvious stabd out as the potential probelm? Thank You!
     
    slinky, Oct 6, 2008
    #1
    1. Advertising

  2. slinky

    rote Guest

    Have you tried setting it to false and see
    Patrick

    "slinky" <> wrote in message
    news:...
    >I had a successfully deployed datagrid reading an XML file and
    > showing the data:
    >
    > Private Function MakeDataView() as DataView
    > Dim myDataSet As New DataSet()
    > myDataSet.ReadXml(Server.MapPath("TimberSales.xml"))
    > Dim view As DataView = New DataView(myDataSet.Tables(0))
    > view.AllowDelete = False
    > view.AllowEdit = True
    > view.AllowNew = False
    > view.Sort = "Year ASC"
    > Return view
    > End Function
    >
    >
    > Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    > Dim view as DataView = MakeDataView()
    > dgTimber.DataSource = view
    > dgTimber.AllowSorting = True
    > dgTimber.DataBind()
    > End Sub
    > ______________________________________________________________________
    >
    >
    > I wanted to add an "Edit" button as desribed at:
    > http://msdn.microsoft.com/en-us/library/aa984288(VS.71).aspx:
    >
    >
    > Private Sub dgTimber_EditCommand(ByVal source As Object, _
    > ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) _
    > Handles dgTimber.EditCommand
    > dgTimber.EditItemIndex = e.Item.ItemIndex
    > dgTimber.DataBind()
    > End Sub
    >
    >
    > Dim newData As String
    > Dim aTextBox As TextBox
    > aTextBox = CType(e.Item.Cells(1).Controls(0), TextBox)
    > **** says "aTextBox" is not declared, (?)
    > newData =
    > aTextBox.Text **** says
    > "newData" is not declared, (?)
    >
    >
    > Private Sub dgTimber_UpdateCommand(ByVal source As Object, _
    > ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) _
    > Handles dgTimber.UpdateCommand
    > Dim quantityCell As TableCell = e.Item.Cells(6)
    > Dim quantityBox As TextBox = _
    > CType(quantityCell.Controls(0), TextBox)
    > Dim quantity As Integer =
    > System.Int32.Parse(quantityBox.Text)
    > dgTimber.EditItemIndex = -1
    > dgTimber.DataBind()
    > End Sub
    >
    >
    > When I hit the Edit Button I get this:
    >
    >
    > Invalid postback or callback argument. Event validation is
    > enabled
    > using <pages enableEventValidation="true"/>
    > in configuration or <%@ Page EnableEventValidation="true" %> in a
    > page. For security purposes, this feature ....etc.
    >
    >
    > Does anything obvious stabd out as the potential probelm? Thank You!
     
    rote, Oct 7, 2008
    #2
    1. Advertising

  3. slinky

    slinky Guest

    Thanks... that worked... now I need to write an event handler for the
    buttons:

    My code within the datagrid describes the buttons:

    <asp:EditCommandColumn ButtonType="PushButton"
    CancelText="Cancel"
    EditText="Edit" UpdateText="Update"
    CausesValidation="false"></asp:EditCommandColumn>

    I'm having difficulty following the tutorial's association with this
    dg's button and this code:

    Private Sub dgTimber_EditCommand(ByVal source As Object, _
    ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) _
    Handles dgTimber.EditCommand
    dgTimber.EditItemIndex = e.Item.ItemIndex
    dgTimber.DataBind()
    End Sub

    Private Sub dgTimber_UpdateCommand(ByVal source As Object, _
    ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) _
    Handles dgTimber.UpdateCommand
    Dim quantityCell As TableCell = e.Item.Cells(6)
    Dim quantityBox As TextBox = _
    CType(quantityCell.Controls(0), TextBox)
    Dim quantity As Integer =
    System.Int32.Parse(quantityBox.Text)
    dgTimber.EditItemIndex = -1
    dgTimber.DataBind()
    End Sub

    Basically what I want is when I hit the edit button a textbox
    displays below the datagrid and the users can type in the new info and
    the button will change to Update upon which pressing that will write
    the constents of the textbox to the database (and a postback refresh
    will show the updated info).


    On Oct 6, 9:13 pm, "rote" <> wrote:
    > Have you tried setting it to false and see
    > Patrick
    >
    > "slinky" <> wrote in message
    >
    > news:...
    >
    >
    >
    > >I had a successfully deployed datagrid reading an XML file and
    > > showing the data:

    >
    > >    Private Function MakeDataView() as DataView
    > >        Dim myDataSet As New DataSet()
    > >        myDataSet.ReadXml(Server.MapPath("TimberSales.xml"))
    > >        Dim view As DataView = New DataView(myDataSet.Tables(0))
    > >        view.AllowDelete = False
    > >        view.AllowEdit = True
    > >        view.AllowNew = False
    > >        view.Sort = "Year ASC"
    > >        Return view
    > >    End Function

    >
    > >    Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    > >        Dim view as DataView = MakeDataView()
    > >        dgTimber.DataSource = view
    > >        dgTimber.AllowSorting = True
    > >        dgTimber.DataBind()
    > >    End Sub
    > > ______________________________________________________________________

    >
    > > I wanted to add an "Edit" button as desribed at:
    > >http://msdn.microsoft.com/en-us/library/aa984288(VS.71).aspx:

    >
    > >    Private Sub dgTimber_EditCommand(ByVal source As Object, _
    > >    ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) _
    > >    Handles dgTimber.EditCommand
    > >        dgTimber.EditItemIndex = e.Item.ItemIndex
    > >        dgTimber.DataBind()
    > >    End Sub

    >
    > >        Dim newData As String
    > >        Dim aTextBox As TextBox
    > >            aTextBox = CType(e.Item.Cells(1).Controls(0), TextBox)
    > > **** says "aTextBox" is not declared, (?)
    > >            newData =
    > > aTextBox.Text                                              **** says
    > > "newData" is not declared, (?)

    >
    > >    Private Sub dgTimber_UpdateCommand(ByVal source As Object, _
    > >    ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) _
    > >    Handles dgTimber.UpdateCommand
    > >        Dim quantityCell As TableCell = e.Item.Cells(6)
    > >        Dim quantityBox As TextBox = _
    > >           CType(quantityCell.Controls(0), TextBox)
    > >        Dim quantity As Integer =
    > > System.Int32.Parse(quantityBox.Text)
    > >        dgTimber.EditItemIndex = -1
    > >        dgTimber.DataBind()
    > >    End Sub

    >
    > > When I hit the Edit Button I get this:

    >
    > >   Invalid postback or callback argument.  Event validation is
    > > enabled
    > > using <pages enableEventValidation="true"/>
    > >   in configuration or <%@ Page EnableEventValidation="true" %> in a
    > > page.  For security purposes, this feature ....etc.

    >
    > > Does anything obvious stabd out as the potential probelm?  Thank You!- Hide quoted text -

    >
    > - Show quoted text -
     
    slinky, Oct 7, 2008
    #3
    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. San Diego Guy
    Replies:
    0
    Views:
    562
    San Diego Guy
    Aug 7, 2003
  2. Sonal
    Replies:
    3
    Views:
    5,547
    Sonal
    Nov 26, 2004
  3. Schultz
    Replies:
    3
    Views:
    576
    =?Utf-8?B?QmlsbCBCb3Jn?=
    Feb 14, 2005
  4. Anup

    MFC prob,..urgent

    Anup, May 20, 2004, in forum: C++
    Replies:
    3
    Views:
    361
    red floyd
    May 20, 2004
  5. Frank Kurka
    Replies:
    8
    Views:
    318
Loading...

Share This Page