all groups > vb.net controls > july 2006 >
vb.net controls :
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 [quoted text, click to view] 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
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
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 [quoted text, click to view] Cas wrote: > With this, it works: > Dim a As String > a = e.Values(4).ToString > > > > <CaffieneRush@gmail.com> schreef in bericht > news:1152563101.065382.296450@m79g2000cwm.googlegroups.com... > > 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 > >
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) <CaffieneRush@gmail.com> schreef in bericht news:1152563101.065382.296450@m79g2000cwm.googlegroups.com... [quoted text, click to view] > 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 >
With this, it works: Dim a As String a = e.Values(4).ToString <CaffieneRush@gmail.com> schreef in bericht news:1152563101.065382.296450@m79g2000cwm.googlegroups.com... [quoted text, click to view] > 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 >
no problem, you helped me .. <Andy.C.Lam@gmail.com> schreef in bericht news:1152628964.564029.207340@p79g2000cwp.googlegroups.com... [quoted text, click to view] > 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 >> >> >> >> <CaffieneRush@gmail.com> schreef in bericht >> news:1152563101.065382.296450@m79g2000cwm.googlegroups.com... >> > 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 >> > >
Don't see what you're looking for? Try a search.
|
|
|