473,595 Members | 2,442 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Row Item in DataView - OnRowDatabound event

I previously had a project working, in which the Gridview was populated by a
DataSet - then, with a DropDownlist in one of the columns, using the
OnrowDataBound event, to populate the DDL with the correct item in the
returned data, I had :
myDDL.SelectedV alue =
IIf(IsDBNull(My DataSet.Rows(e. Row.RowIndex).I tem("Fieldname" )),
vbNullString, MyDataSet.Rows( e.Row.RowIndex) .Item("Fieldnam e"))

In my new application, I'm using a DataView to populate the Gridview, since
there are filters which need to be used, dynamically - - I tried the same
kind of thing, but I'm not sure how it would work with a DataView:

Here's what I have that doesn't work:
..SelectedValue = IIf(IsDBNull(my DV.Item(e.Row.R owIndex).Item(" Fieldname")),
vbNullString, myDV.Item(e.Row .RowIndex).Item ("Fieldname" ))

myDVis saved in cache, and retrieved when needed. However, I get the dreaded
"Object Reference not set to an instance of the object' error when it gets
to that line)
(and yes, this all between an "If e.Row.RowType = DataControlRowT ype.DataRow
Then" block

Any ideas on how to get that to work?
Nov 9 '06 #1
3 6421
This is really the old way of doing things. The new way would be to first
convert the gridview column that contains the dropdown to a template column,
add a dropdown control, add an sqldatasource, bind the sqldatasource to the
database to get the column field and then bind the dropdown to
sqldatasource. The benefit is zero code and zero event hookup.
Here's what I have that doesn't work:
.SelectedValue =
IIf(IsDBNull(my DV.Item(e.Row.R owIndex).Item(" Fieldname")),
vbNullString, myDV.Item(e.Row .RowIndex).Item ("Fieldname" ))
I believe there is a bug here. You are using the row index to index into the
dataview items. There's no guarantee that the two will map to the same hence
the null object error. You'd be better served mapping to the respective row
of the dataview object instead of indexing into its item collection.
Something like myDV.Tables.Row s(e.Row.Rowinde x should get you started on the
right path.
--
_______________ _________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------
"Elmo Watson" <sp*****@yahoo. comwrote in message
news:eV******** ******@TK2MSFTN GP03.phx.gbl...
>I previously had a project working, in which the Gridview was populated by
a
DataSet - then, with a DropDownlist in one of the columns, using the
OnrowDataBound event, to populate the DDL with the correct item in the
returned data, I had :
myDDL.SelectedV alue =
IIf(IsDBNull(My DataSet.Rows(e. Row.RowIndex).I tem("Fieldname" )),
vbNullString, MyDataSet.Rows( e.Row.RowIndex) .Item("Fieldnam e"))

In my new application, I'm using a DataView to populate the Gridview,
since
there are filters which need to be used, dynamically - - I tried the same
kind of thing, but I'm not sure how it would work with a DataView:

Here's what I have that doesn't work:
.SelectedValue =
IIf(IsDBNull(my DV.Item(e.Row.R owIndex).Item(" Fieldname")),
vbNullString, myDV.Item(e.Row .RowIndex).Item ("Fieldname" ))

myDVis saved in cache, and retrieved when needed. However, I get the
dreaded
"Object Reference not set to an instance of the object' error when it gets
to that line)
(and yes, this all between an "If e.Row.RowType =
DataControlRowT ype.DataRow
Then" block

Any ideas on how to get that to work?


Nov 9 '06 #2
I agree with you to a point, but not all situations provide the choice for
that one scenario. As far as I know, the DataSource controls either provide
a DataSet or DataReader.
The problem is, that, at this point, it can't be re-constructed - this is
all object based, and the connection is made using an object, a DataView is
returned, so filters can be applied.
I tried myDV.Table.Rows (e.row.RowIndex )
however I get the same error.

"Alvin Bruney [MVP]" <www.lulu.com/owcwrote in message
news:Os******** ******@TK2MSFTN GP04.phx.gbl...
This is really the old way of doing things. The new way would be to first
convert the gridview column that contains the dropdown to a template
column,
add a dropdown control, add an sqldatasource, bind the sqldatasource to
the
database to get the column field and then bind the dropdown to
sqldatasource. The benefit is zero code and zero event hookup.
Here's what I have that doesn't work:
.SelectedValue =
IIf(IsDBNull(my DV.Item(e.Row.R owIndex).Item(" Fieldname")),
vbNullString, myDV.Item(e.Row .RowIndex).Item ("Fieldname" ))
I believe there is a bug here. You are using the row index to index into
the
dataview items. There's no guarantee that the two will map to the same
hence
the null object error. You'd be better served mapping to the respective
row
of the dataview object instead of indexing into its item collection.
Something like myDV.Tables.Row s(e.Row.Rowinde x should get you started on
the
right path.
--
_______________ _________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------
"Elmo Watson" <sp*****@yahoo. comwrote in message
news:eV******** ******@TK2MSFTN GP03.phx.gbl...
I previously had a project working, in which the Gridview was populated
by
a
DataSet - then, with a DropDownlist in one of the columns, using the
OnrowDataBound event, to populate the DDL with the correct item in the
returned data, I had :
myDDL.SelectedV alue =
IIf(IsDBNull(My DataSet.Rows(e. Row.RowIndex).I tem("Fieldname" )),
vbNullString, MyDataSet.Rows( e.Row.RowIndex) .Item("Fieldnam e"))

In my new application, I'm using a DataView to populate the Gridview,
since
there are filters which need to be used, dynamically - - I tried the
same
kind of thing, but I'm not sure how it would work with a DataView:

Here's what I have that doesn't work:
.SelectedValue =
IIf(IsDBNull(my DV.Item(e.Row.R owIndex).Item(" Fieldname")),
vbNullString, myDV.Item(e.Row .RowIndex).Item ("Fieldname" ))

myDVis saved in cache, and retrieved when needed. However, I get the
dreaded
"Object Reference not set to an instance of the object' error when it
gets
to that line)
(and yes, this all between an "If e.Row.RowType =
DataControlRowT ype.DataRow
Then" block

Any ideas on how to get that to work?


Nov 10 '06 #3
Couple things wrong in your code. I provide the correct syntax below -
you'll need to translate into vb. Additionally, the rowindex isn't valid for
the gridview header, it actually is set to -1. That is an invalid index in
the dataview. You'll need to trap for that condition to avoid the header
row. Here's working code.

DataView view = (DataView)Sessi on["view"];

if (view == null)

{

Response.Write( "<script>alert( 'empty')</script>");

}

else

{

if (e.Row.RowIndex -1)

{

object[] items = view.Table.Rows[e.Row.RowIndex].ItemArray;

string str = items[3].ToString();

}

}
--
_______________ _________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------
"Elmo Watson" <sp*****@yahoo. comwrote in message
news:uK******** ******@TK2MSFTN GP02.phx.gbl...
>I agree with you to a point, but not all situations provide the choice for
that one scenario. As far as I know, the DataSource controls either
provide
a DataSet or DataReader.
The problem is, that, at this point, it can't be re-constructed - this is
all object based, and the connection is made using an object, a DataView
is
returned, so filters can be applied.
I tried myDV.Table.Rows (e.row.RowIndex )
however I get the same error.

"Alvin Bruney [MVP]" <www.lulu.com/owcwrote in message
news:Os******** ******@TK2MSFTN GP04.phx.gbl...
>This is really the old way of doing things. The new way would be to first
convert the gridview column that contains the dropdown to a template
column,
>add a dropdown control, add an sqldatasource, bind the sqldatasource to
the
>database to get the column field and then bind the dropdown to
sqldatasourc e. The benefit is zero code and zero event hookup.
Here's what I have that doesn't work:
.SelectedValue =
IIf(IsDBNull(my DV.Item(e.Row.R owIndex).Item(" Fieldname")),
vbNullString, myDV.Item(e.Row .RowIndex).Item ("Fieldname" ))
I believe there is a bug here. You are using the row index to index into
the
>dataview items. There's no guarantee that the two will map to the same
hence
>the null object error. You'd be better served mapping to the respective
row
>of the dataview object instead of indexing into its item collection.
Something like myDV.Tables.Row s(e.Row.Rowinde x should get you started on
the
>right path.
--
______________ __________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------
"Elmo Watson" <sp*****@yahoo. comwrote in message
news:eV******* *******@TK2MSFT NGP03.phx.gbl.. .
>I previously had a project working, in which the Gridview was populated
by
>a
DataSet - then, with a DropDownlist in one of the columns, using the
OnrowDataBound event, to populate the DDL with the correct item in the
returned data, I had :
myDDL.SelectedV alue =
IIf(IsDBNull(My DataSet.Rows(e. Row.RowIndex).I tem("Fieldname" )),
vbNullString, MyDataSet.Rows( e.Row.RowIndex) .Item("Fieldnam e"))

In my new application, I'm using a DataView to populate the Gridview,
since
there are filters which need to be used, dynamically - - I tried the
same
kind of thing, but I'm not sure how it would work with a DataView:

Here's what I have that doesn't work:
.SelectedValue =
IIf(IsDBNull(my DV.Item(e.Row.R owIndex).Item(" Fieldname")),
vbNullString, myDV.Item(e.Row .RowIndex).Item ("Fieldname" ))

myDVis saved in cache, and retrieved when needed. However, I get the
dreaded
"Object Reference not set to an instance of the object' error when it
gets
to that line)
(and yes, this all between an "If e.Row.RowType =
DataControlRowT ype.DataRow
Then" block

Any ideas on how to get that to work?




Nov 11 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
341
by: Randy | last post by:
Hello All, I'm trying to use a DataView and in the rowfilter, base it on two fields in the table. I can't find any examples on this. Is there a way to do it. I'm talking about something like... DataView dv = new DataView(myTable, "field1 like '" + buffer + "*' and field2 = true", "field1", DataViewRowState.CurrentRows); The above doesn't seem to work. I'm not sure if I'm supposed to use the "and" in it...also I'm not sure how to do the...
6
1628
by: enrique | last post by:
Hello, I simpy want to place a record ID into a session variable. I know how to create session variables, I'm just can't figure out the syntax for the record item when I'm working with a dataset. I'm using vb. session(sessionName) = recordID 'from dataset or dataview Thanks, Enrique
1
2684
by: Gunjan Garg | last post by:
Hello All, I am working to create a generic datagrid which accepts a datasource(ListData - This is our own datatype) and depending on the calling program customizes itself for sorting, paginantion or accepting the add and remove item events. What i am observing is that none of the vents are happening... (Sort, page, or item). I am sure I am missing something basic here... Need help... Thanks much
9
4449
by: Kay | last post by:
Hi all, Could you tell me the best way to add a blank item(as first item) in a data binded combo box? Because I think I didn't do it right and it generate an error if the second item(after the top blank item) is selected by using Combo.SelectedValue : "Specified argument was out of the range of valid values. Parameter name: '-2147483648' is not a valid value for 'index'.
5
3931
by: Earl | last post by:
Noting first that I'm coming from VS2003 and VB.Net ... Using an untyped dataset, I create a dataview. When I try to use the Item property, "Item" does not appear on the Intellisense dropdown and I also get the build error "'System.Data.DataView' does not containt a definition for 'Item'." The documentation for VS2005 does show Item as a property of a dataview -- can anyone see the issue? DataView dvContacts = new DataView(ds.Tables);...
2
1571
by: Aconquija | last post by:
Hello, I have run into an issue when using the OnRowDataBound event to apply conditional formatting to a row. I need to check a specific column to see if the value from the database is null. Without conditional formatting the page just shows empty text in the table when the database column is null. I figured the text value would be equivalent to "" but that doesn't work. Here is a code snippet: Protected Sub Grid_Databound(ByVal sender...
2
7222
by: =?Utf-8?B?Z2FuZQ==?= | last post by:
Hi, In a gridview, How can i display different columns between item and edit modes. For eg. i have a sql that returns productname, categoryname, etc. In viewmode, i need to display only productname column and not categoryname column. Again in Edit mode, i need display/edit category name only. But not productname column shouldnt be displayed/editable. In visual studio 2005, I tried converting the columns to template fields and
1
9487
by: =?Utf-8?B?Q2hyaXMgRmluaw==?= | last post by:
I am trying to dynamically add a control within an itemtemplate container in a gridview and need some assistance. For example, my goal is to evaluate a column's value in a datagrid row and depending on it's value dynamically add a few hyperlink controls to within the template field. I'm familiar with doing this in .NET 1.1 using the itemondatabound event and interrogating the datagrid and am looking for a similiar way to do this with...
0
2141
by: Pravin Pujari | last post by:
Hi All, I am using .net framework 1.1 and c#. I have one problem regarding dataview. I have one dataview to which sorting may be applied or may not be applied. I have one UI component where I am displaying the dataview. All rows in dataview are displayed in the sequence as they appear in dataview. i.e. there is direct mapping between dataview rows and UI rows. I have subscribed ColumnChanged event of the datatable on which dataview is...
0
8262
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8379
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6675
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5839
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5421
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3875
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3915
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2391
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1491
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.