how to check the value of a field on each row?

  • Thread starter Thread starter phil
  • Start date Start date
P

phil

Hi,

The aspx file contains a datasource and a gridview.
The (only) field is a boolean type (true/false).
Now, when the value of the field is 'true' something must happen (e.g.
Response.Write("this is true") ).
So i used the server-event 'GridView1_RowCreated' but how can i check the
value of the field on each row?
I tried this code below, but it doesn't work ...
Thanks
Phil

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\mydb.mdb"
ProviderName="System.Data.OleDb" SelectCommand="SELECT field1 from
mytable"></asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1"
<Columns><asp:BoundField DataField="myfield" /> </Columns>
</asp:GridView>

The code-behind:
Protected Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated
Dim a As Object
a = GridView1.Columns(5)
If a.Equals(True) Then
Response.Write("ok")
End If
End Sub
 
Set a breakpoint on the a = line and check the value of the GridView line to
ensure you are working with the correct value. I know by the time an older
1.1 DataView had items, they were all cast as strings (have not played with
a row level event with a GridView, however.

If I am correct, you will find that either a) you have the wrong column as
you are thinking 1 based instead of 0 based and/or b) you are dealing with a
"True" not True and the implicit cast is not valid. :-)

If a = True, try

a = Boolean.Parse(GridView1.Columns(5))

or similar. With a debugger and a bit of tweaking, you will get the value
out correctly.

--
Gregory A. Beamer

*************************************************
Think Outside the Box!
*************************************************
 
Hi, thanks for replying ....

I changed the code and this gives the name of the right column (index must
be 0 of course and not 5).
Dim a As DataControlField
a = GridView1.Columns(0)

But my problem remains the same: how can i check its value?
There is nothing i can put after 'Columns(0).' , like "value" or something
....

Thanks again
 
Back
Top