how to change labelvalue when deleting row in gridview?

Discussion in 'ASP .Net Datagrid Control' started by Cas, Jul 10, 2006.

  1. Cas

    Cas Guest

    Hello,

    My gridview has the option ShowDeleteButton="True".
    There is also a label which renders the amounts of records.

    What i'm trying tot do is: when i delete a row, the amount of records must
    be adapted in function of the value of a field.
    If the value of the field="black" then it must be decreased with 1,
    otherwise it must be decreased with 2.

    In the code-behind, i started with this, but cant' go further:

    Friend rec As integer
    Protected Sub GridView1_RowDeleted(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.GridViewDeletedEventArgs) Handles
    GridView1.RowDeleted
    dim a as ??
    a = gridview1. ??? .ToString
    if a="black" then
    rec = rec - 1
    else
    rec=rec-2
    end if

    Label1.Text = rec
    End Sub

    I guess i use the right event (or is it GridView1_RowDeleting?).
    If you can replace the ?? with the appropriate code, it would be great!
    Thanks
    Cas
     
    Cas, Jul 10, 2006
    #1
    1. Advertising

  2. Cas

    Guest

    Re: how to change labelvalue when deleting row in gridview?

    Friend rec As integer
    Protected Sub GridView1_RowDeleted(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.GridViewDeletedEventArgs) Handles
    GridView1.RowDeleted

    dim a as DictionaryEntry
    a = e.Keys(0) 'supposing you're checking the first primary key field
    of the current row
    'a = e.Values(1) 'supposing you're checking the second non-key field
    of the row
    'If you don't know the position of the field then you'll need to use a
    for each loop
    'the field.
    if a.Value ="black" then
    rec = rec - 1
    else
    rec=rec-2
    end if

    Label1.Text = rec
    End Sub

    Cas wrote:
    > Hello,
    >
    > My gridview has the option ShowDeleteButton="True".
    > There is also a label which renders the amounts of records.
    >
    > What i'm trying tot do is: when i delete a row, the amount of records must
    > be adapted in function of the value of a field.
    > If the value of the field="black" then it must be decreased with 1,
    > otherwise it must be decreased with 2.
    >
    > In the code-behind, i started with this, but cant' go further:
    >
    > Friend rec As integer
    > Protected Sub GridView1_RowDeleted(ByVal sender As Object, ByVal e As
    > System.Web.UI.WebControls.GridViewDeletedEventArgs) Handles
    > GridView1.RowDeleted
    > dim a as ??
    > a = gridview1. ??? .ToString
    > if a="black" then
    > rec = rec - 1
    > else
    > rec=rec-2
    > end if
    >
    > Label1.Text = rec
    > End Sub
    >
    > I guess i use the right event (or is it GridView1_RowDeleting?).
    > If you can replace the ?? with the appropriate code, it would be great!
    > Thanks
    > Cas
     
    , Jul 10, 2006
    #2
    1. Advertising

  3. Cas

    Cas Guest

    Re: how to change labelvalue when deleting row in gridview?

    Thanks for replying,

    I tried what you told me, but it generated for any value (e.keys(0) or
    e.Values(1 to 5) because there are 6 fields in total) this:
    System.InvalidCastException: Specified cast is not valid

    The delete line in the aspx file is this:
    DeleteCommand="DELETE FROM studres WHERE resnr = @resnr" (resnr = primary
    field)







    <> schreef in bericht
    news:...
    > Friend rec As integer
    > Protected Sub GridView1_RowDeleted(ByVal sender As Object, ByVal e As
    > System.Web.UI.WebControls.GridViewDeletedEventArgs) Handles
    > GridView1.RowDeleted
    >
    > dim a as DictionaryEntry
    > a = e.Keys(0) 'supposing you're checking the first primary key field
    > of the current row
    > 'a = e.Values(1) 'supposing you're checking the second non-key field
    > of the row
    > 'If you don't know the position of the field then you'll need to use a
    > for each loop
    > 'the field.
    > if a.Value ="black" then
    > rec = rec - 1
    > else
    > rec=rec-2
    > end if
    >
    > Label1.Text = rec
    > End Sub
    >
    > Cas wrote:
    >> Hello,
    >>
    >> My gridview has the option ShowDeleteButton="True".
    >> There is also a label which renders the amounts of records.
    >>
    >> What i'm trying tot do is: when i delete a row, the amount of records
    >> must
    >> be adapted in function of the value of a field.
    >> If the value of the field="black" then it must be decreased with 1,
    >> otherwise it must be decreased with 2.
    >>
    >> In the code-behind, i started with this, but cant' go further:
    >>
    >> Friend rec As integer
    >> Protected Sub GridView1_RowDeleted(ByVal sender As Object, ByVal e As
    >> System.Web.UI.WebControls.GridViewDeletedEventArgs) Handles
    >> GridView1.RowDeleted
    >> dim a as ??
    >> a = gridview1. ??? .ToString
    >> if a="black" then
    >> rec = rec - 1
    >> else
    >> rec=rec-2
    >> end if
    >>
    >> Label1.Text = rec
    >> End Sub
    >>
    >> I guess i use the right event (or is it GridView1_RowDeleting?).
    >> If you can replace the ?? with the appropriate code, it would be great!
    >> Thanks
    >> Cas

    >
     
    Cas, Jul 11, 2006
    #3
  4. Cas

    Cas Guest

    Re: how to change labelvalue when deleting row in gridview?

    With this, it works:
    Dim a As String
    a = e.Values(4).ToString



    <> schreef in bericht
    news:...
    > Friend rec As integer
    > Protected Sub GridView1_RowDeleted(ByVal sender As Object, ByVal e As
    > System.Web.UI.WebControls.GridViewDeletedEventArgs) Handles
    > GridView1.RowDeleted
    >
    > dim a as DictionaryEntry
    > a = e.Keys(0) 'supposing you're checking the first primary key field
    > of the current row
    > 'a = e.Values(1) 'supposing you're checking the second non-key field
    > of the row
    > 'If you don't know the position of the field then you'll need to use a
    > for each loop
    > 'the field.
    > if a.Value ="black" then
    > rec = rec - 1
    > else
    > rec=rec-2
    > end if
    >
    > Label1.Text = rec
    > End Sub
    >
    > Cas wrote:
    >> Hello,
    >>
    >> My gridview has the option ShowDeleteButton="True".
    >> There is also a label which renders the amounts of records.
    >>
    >> What i'm trying tot do is: when i delete a row, the amount of records
    >> must
    >> be adapted in function of the value of a field.
    >> If the value of the field="black" then it must be decreased with 1,
    >> otherwise it must be decreased with 2.
    >>
    >> In the code-behind, i started with this, but cant' go further:
    >>
    >> Friend rec As integer
    >> Protected Sub GridView1_RowDeleted(ByVal sender As Object, ByVal e As
    >> System.Web.UI.WebControls.GridViewDeletedEventArgs) Handles
    >> GridView1.RowDeleted
    >> dim a as ??
    >> a = gridview1. ??? .ToString
    >> if a="black" then
    >> rec = rec - 1
    >> else
    >> rec=rec-2
    >> end if
    >>
    >> Label1.Text = rec
    >> End Sub
    >>
    >> I guess i use the right event (or is it GridView1_RowDeleting?).
    >> If you can replace the ?? with the appropriate code, it would be great!
    >> Thanks
    >> Cas

    >
     
    Cas, Jul 11, 2006
    #4
  5. Cas

    Cas Guest

    Re: how to change labelvalue when deleting row in gridview?

    no problem, you helped me ..

    <> schreef in bericht
    news:...
    > My apologies for forgetting to convert the key/non-key values back to a
    > string.
    > I don't have the docs in front of me but I assumed that taking the
    > Value of a DictionaryEntry should return the actual value.
    >
    > I'm glad you solved the problem.
    >
    > Regards.
    > Andy
    >
    > Cas wrote:
    >> With this, it works:
    >> Dim a As String
    >> a = e.Values(4).ToString
    >>
    >>
    >>
    >> <> schreef in bericht
    >> news:...
    >> > Friend rec As integer
    >> > Protected Sub GridView1_RowDeleted(ByVal sender As Object, ByVal e As
    >> > System.Web.UI.WebControls.GridViewDeletedEventArgs) Handles
    >> > GridView1.RowDeleted
    >> >
    >> > dim a as DictionaryEntry
    >> > a = e.Keys(0) 'supposing you're checking the first primary key field
    >> > of the current row
    >> > 'a = e.Values(1) 'supposing you're checking the second non-key field
    >> > of the row
    >> > 'If you don't know the position of the field then you'll need to use a
    >> > for each loop
    >> > 'the field.
    >> > if a.Value ="black" then
    >> > rec = rec - 1
    >> > else
    >> > rec=rec-2
    >> > end if
    >> >
    >> > Label1.Text = rec
    >> > End Sub
    >> >
    >> > Cas wrote:
    >> >> Hello,
    >> >>
    >> >> My gridview has the option ShowDeleteButton="True".
    >> >> There is also a label which renders the amounts of records.
    >> >>
    >> >> What i'm trying tot do is: when i delete a row, the amount of records
    >> >> must
    >> >> be adapted in function of the value of a field.
    >> >> If the value of the field="black" then it must be decreased with 1,
    >> >> otherwise it must be decreased with 2.
    >> >>
    >> >> In the code-behind, i started with this, but cant' go further:
    >> >>
    >> >> Friend rec As integer
    >> >> Protected Sub GridView1_RowDeleted(ByVal sender As Object, ByVal e As
    >> >> System.Web.UI.WebControls.GridViewDeletedEventArgs) Handles
    >> >> GridView1.RowDeleted
    >> >> dim a as ??
    >> >> a = gridview1. ??? .ToString
    >> >> if a="black" then
    >> >> rec = rec - 1
    >> >> else
    >> >> rec=rec-2
    >> >> end if
    >> >>
    >> >> Label1.Text = rec
    >> >> End Sub
    >> >>
    >> >> I guess i use the right event (or is it GridView1_RowDeleting?).
    >> >> If you can replace the ?? with the appropriate code, it would be
    >> >> great!
    >> >> Thanks
    >> >> Cas
    >> >

    >
     
    Cas, Jul 11, 2006
    #5
    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.

Share This Page