Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > GridView SelectedIndexChanged question

Reply
Thread Tools

GridView SelectedIndexChanged question

 
 
David C
Guest
Posts: n/a
 
      10-24-2009
I have a GridView that I want to show or hide LinkButtons that exist outside
of the GridView based on a data column in the GridView when that row is
selected. I have the code below for the SelectedIndexChanged event but it
always falls through to the False condition. The data column named
VoidCheck is a SQL Server bit data type. Can someone help me spot the
problem? Thanks in advance.

David

Protected Sub gvVendorChecks_SelectedIndexChanged(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
gvVendorChecks.SelectedIndexChanged
' Get the currently selected row using the SelectedRow property.
Dim row As GridViewRow = gvVendorChecks.SelectedRow

If row.RowState = DataControlRowState.Selected Then
Dim bolvoid As Boolean =
Convert.ToBoolean(DataBinder.Eval(row.DataItem, "VoidCheck"))
If bolvoid = True Then
' voided check selected so show the remove void button
LBtnRemoveVoid.Visible = True
LBtnVoidCheck.Visible = False
Else
LBtnRemoveVoid.Visible = False
LBtnVoidCheck.Visible = True
End If
End If
End Sub


 
Reply With Quote
 
 
 
 
Alexey Smirnov
Guest
Posts: n/a
 
      10-24-2009
On Oct 24, 2:59*pm, "David C" <(E-Mail Removed)> wrote:
> I have a GridView that I want to show or hide LinkButtons that exist outside
> of the GridView based on a data column in the GridView when that row is
> selected. *I have the code below for the SelectedIndexChanged event but it
> always falls through to the False condition. *The data column named
> VoidCheck is a SQL Server bit data type. *Can someone help me spot the
> problem? *Thanks in advance.
>
> David
>
> * * Protected Sub gvVendorChecks_SelectedIndexChanged(ByVal sender As
> Object, ByVal e As System.EventArgs) Handles
> gvVendorChecks.SelectedIndexChanged
> * * * * ' Get the currently selected row using the SelectedRow property.
> * * * * Dim row As GridViewRow = gvVendorChecks.SelectedRow
>
> * * * * If row.RowState = DataControlRowState.Selected Then
> * * * * * * Dim bolvoid As Boolean =
> Convert.ToBoolean(DataBinder.Eval(row.DataItem, "VoidCheck"))
> * * * * * * If bolvoid = True Then
> * * * * * * * * ' voided check selected so show the remove void button
> * * * * * * * * LBtnRemoveVoid.Visible = True
> * * * * * * * * LBtnVoidCheck.Visible = False
> * * * * * * Else
> * * * * * * * * LBtnRemoveVoid.Visible = False
> * * * * * * * * LBtnVoidCheck.Visible = True
> * * * * * * End If
> * * * * End If
> * * End Sub


The RowType property is a bitwise combination of the values and not a
boolean. Either remove

** If row.RowState = DataControlRowState.Selected Then **

because it makes no sense, or replace it by

** If (row.RowState And DataControlRowState.Edit) > 0 Then **

Hope this helps.
 
Reply With Quote
 
 
 
 
David C
Guest
Posts: n/a
 
      10-24-2009
I changed the first If statement but for some reason the boolean check
always returns false even though I can see the checkbox is checked on some
of the rows I select. Can you see anything wrong with the boolean statement
with bolvoid setting? Thanks.

David

"Alexey Smirnov" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
On Oct 24, 2:59 pm, "David C" <(E-Mail Removed)> wrote:
> I have a GridView that I want to show or hide LinkButtons that exist
> outside
> of the GridView based on a data column in the GridView when that row is
> selected. I have the code below for the SelectedIndexChanged event but it
> always falls through to the False condition. The data column named
> VoidCheck is a SQL Server bit data type. Can someone help me spot the
> problem? Thanks in advance.
>
> David
>
> Protected Sub gvVendorChecks_SelectedIndexChanged(ByVal sender As
> Object, ByVal e As System.EventArgs) Handles
> gvVendorChecks.SelectedIndexChanged
> ' Get the currently selected row using the SelectedRow property.
> Dim row As GridViewRow = gvVendorChecks.SelectedRow
>
> If row.RowState = DataControlRowState.Selected Then
> Dim bolvoid As Boolean =
> Convert.ToBoolean(DataBinder.Eval(row.DataItem, "VoidCheck"))
> If bolvoid = True Then
> ' voided check selected so show the remove void button
> LBtnRemoveVoid.Visible = True
> LBtnVoidCheck.Visible = False
> Else
> LBtnRemoveVoid.Visible = False
> LBtnVoidCheck.Visible = True
> End If
> End If
> End Sub


The RowType property is a bitwise combination of the values and not a
boolean. Either remove

** If row.RowState = DataControlRowState.Selected Then **

because it makes no sense, or replace it by

** If (row.RowState And DataControlRowState.Edit) > 0 Then **

Hope this helps.


 
Reply With Quote
 
Alexey Smirnov
Guest
Posts: n/a
 
      10-24-2009
On Oct 24, 10:12*pm, "David C" <(E-Mail Removed)> wrote:
> I changed the first If statement but for some reason the boolean check
> always returns false even though I can see the checkbox is checked on some
> of the rows I select. Can you see anything wrong with the boolean statement
> with bolvoid setting? *Thanks.
>


You mean, in the following line is always false?

Dim bolvoid As Boolean =
Convert.ToBoolean(DataBinder.Eval(row.DataItem, "VoidCheck"))
 
Reply With Quote
 
David C
Guest
Posts: n/a
 
      10-25-2009

"Alexey Smirnov" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
On Oct 24, 10:12 pm, "David C" <(E-Mail Removed)> wrote:
> I changed the first If statement but for some reason the boolean check
> always returns false even though I can see the checkbox is checked on some
> of the rows I select. Can you see anything wrong with the boolean
> statement
> with bolvoid setting? Thanks.
>


You mean, in the following line is always false?

Dim bolvoid As Boolean =
Convert.ToBoolean(DataBinder.Eval(row.DataItem, "VoidCheck"))

Yes. And when I check the actual database record the VoidCheck column = 1


 
Reply With Quote
 
Alexey Smirnov
Guest
Posts: n/a
 
      10-25-2009
On Oct 25, 1:36*pm, "David C" <(E-Mail Removed)> wrote:
> Yes. And when I check the actual database record the VoidCheck column = 1


Before that line add

Response.Write ("VoidCheck=" & DataBinder.Eval(row.DataItem,
"VoidCheck"))

and see what it would return. I suppose it will be "VoidCheck=0"
 
Reply With Quote
 
David C
Guest
Posts: n/a
 
      10-25-2009

"Alexey Smirnov" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
On Oct 25, 1:36 pm, "David C" <(E-Mail Removed)> wrote:
> Yes. And when I check the actual database record the VoidCheck column = 1


Before that line add

Response.Write ("VoidCheck=" & DataBinder.Eval(row.DataItem,
"VoidCheck"))

and see what it would return. I suppose it will be "VoidCheck=0"

Yes, that is what it returned. I even tried converting to integer and it
still returns 0.


 
Reply With Quote
 
Alexey Smirnov
Guest
Posts: n/a
 
      10-26-2009
On Oct 25, 8:11*pm, "David C" <(E-Mail Removed)> wrote:
> "Alexey Smirnov" <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed)...
> On Oct 25, 1:36 pm, "David C" <(E-Mail Removed)> wrote:
>
> > Yes. And when I check the actual database record the VoidCheck column = 1

>
> Before that line add
>
> Response.Write ("VoidCheck=" & DataBinder.Eval(row.DataItem,
> "VoidCheck"))
>
> and see what it would return. I suppose it will be "VoidCheck=0"
>
> Yes, that is what it returned. *I even tried converting to integer and it
> still returns 0.


Ok, but this means there is no error. Convert.ToBoolean(0) equals to
false and your [if] statement will not be executed. You should check
an ID or a DataKey of the row you check in DataBinder.Eval
(row.DataItem,"VoidCheck").

>> I check the actual database record the VoidCheck column = 1


It's another record, and not the one you have in the line with
DataBinder.Eval(row.DataItem,"VoidCheck")
 
Reply With Quote
 
David C
Guest
Posts: n/a
 
      10-26-2009

"Alexey Smirnov" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
On Oct 25, 8:11 pm, "David C" <(E-Mail Removed)> wrote:
> "Alexey Smirnov" <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed)...
> On Oct 25, 1:36 pm, "David C" <(E-Mail Removed)> wrote:
>
> > Yes. And when I check the actual database record the VoidCheck column =
> > 1

>
> Before that line add
>
> Response.Write ("VoidCheck=" & DataBinder.Eval(row.DataItem,
> "VoidCheck"))
>
> and see what it would return. I suppose it will be "VoidCheck=0"
>
> Yes, that is what it returned. I even tried converting to integer and it
> still returns 0.


Ok, but this means there is no error. Convert.ToBoolean(0) equals to
false and your [if] statement will not be executed. You should check
an ID or a DataKey of the row you check in DataBinder.Eval
(row.DataItem,"VoidCheck").

>> I check the actual database record the VoidCheck column = 1


It's another record, and not the one you have in the line with
DataBinder.Eval(row.DataItem,"VoidCheck")

I thought that the following puts you on the selected row. What am I
missing?

If row.RowState = DataControlRowState.Selected Then

-David


 
Reply With Quote
 
Alexey Smirnov
Guest
Posts: n/a
 
      10-26-2009
On Oct 26, 2:35*pm, "David C" <(E-Mail Removed)> wrote:
>
> I thought that the following puts you on the selected row. *What am I
> missing?
>
> If row.RowState = DataControlRowState.Selected Then
>


David,

The RowState can be a bitwise combination of the 4 following values:

DataControlRowState.Normal (=0)
DataControlRowState.Alternate (=1)
DataControlRowState.Selected (=2)
DataControlRowState.Edit (=4)
DataControlRowState.Insert (=

This means that when you selected an alternating row, then RowState is
equal to (2+1) and in this case

row.RowState (2+1) <> DataControlRowState.Selected (2)

Please look at the examples on MSDN

http://msdn.microsoft.com/en-us/libr....rowstate.aspx

You need to check selection in the following way:

If (e.Row.RowState And DataControlRowState.Selected) > 0 Then

OR like this

If e.Row.RowState = (DataControlRowState.Normal Xor
DataControlRowState.Selected) OrElse e.Row.RowState =
(DataControlRowState.Alternate Xor DataControlRowState.Selected) Then

Hope this helps
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: GridView SelectedIndexChanged question Alexey Smirnov ASP .Net 0 10-24-2009 01:13 PM
Gridview - Issue with selectedindexchanged graphicsxp ASP .Net 0 07-11-2006 09:37 AM
Raising SelectedIndexChanged event in a gridview =?Utf-8?B?LU1U?= ASP .Net 2 06-06-2006 07:32 PM
GridView SelectedIndexChanged value sck10 ASP .Net 1 04-03-2006 09:07 AM
SelectedIndexChanged event not responding on selecting gridview =?Utf-8?B?QVQ=?= ASP .Net 1 04-01-2005 09:37 PM



Advertisments