|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
how to change labelvalue when deleting row in gridview?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 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: Show quoteHide quote > 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) <CaffieneR***@gmail.com> schreef in bericht Show quoteHide quote 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 > With this, it works:
Dim a As String a = e.Values(4).ToString <CaffieneR***@gmail.com> schreef in bericht Show quoteHide quote 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 > 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: Show quoteHide quote > With this, it works: > Dim a As String > a = e.Values(4).ToString > > > > <CaffieneR***@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 > > no problem, you helped me ..
<Andy.C.***@gmail.com> schreef in bericht Show quoteHide quote news:1152628964.564029.207340@p79g2000cwp.googlegroups.com... > 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 >> >> >> >> <CaffieneR***@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 >> > >
Dropdown List doesn't know what's in it's list
Max Number of Web Controls Per Page??? How to put an image in a GridView textfield not recognized in gridview menu control with XML file creative scroll bar for asp.net Datagrids and User Controls Datagrid Control in VS2005 GridView columns don't respect width or wrap properties! How do I use multiple siteMaps? |
|||||||||||||||||||||||