how to change labelvalue when deleting row in gridview?

C

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
 
C

CaffieneRush

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
 
C

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)
 
C

Cas

no problem, you helped me ..

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,016
Latest member
TatianaCha

Latest Threads

Top