Ask a Question related to ASP.NET Data Grid Control, Design and Development.
-
Nathan Sokalski #1
Accessing the current DataRow of the DataSource from ItemDataBound
I want to access the DataRow used in DataBinding from the ItemDataBound
event. In my case, the reason for doing this is to determine whether I need
to make a word singular or plural. How can I do this? Thanks.
--
Nathan Sokalski
[email]njsokalski@hotmail.com[/email]
[url]http://www.nathansokalski.com/[/url]
Nathan Sokalski Guest
-
Accessing DataRow Items by Name in Edit/Update/Delete Event
Hi there. I have a small problem with DataGrid in ASP.NET & C#. In the ItemDataBound Event I can use the following code DataRowView drvSE =... -
Accessing data from C# code-behind in the ItemDataBound Event
Hello: If I want to access a particular column of data that is bound to a datagrid from within the ItemDataBound Event, how would I do that? I... -
Accessing the current datasource row and column?
How would i go about accessing a column in the currently binding row in a datagrids datasource the following code does not give me access to the... -
Accessing a datasource at a network location
Julie, I believe you've run into a permissions problem. Your web application is most likely running under the local account IUSR_<machinename>.... -
accessing current written record
See @@IDENTITY and SCOPE_IDENTITY( ) in SQL Server Books Online. -- HTH, Vyas, MVP (SQL Server) http://vyaskn.tripod.com/ What hardware is... -
Adam Knight #2
Re: Accessing the current DataRow of the DataSource from ItemDataBound
Use the DataGridItems DataItem method.
It Returns a reference to the source data row as a DataRowView object.
Hope it helps.
Adam
Adam Knight Guest
-
Ken Tucker [MVP] #3
Re: Accessing the current DataRow of the DataSource from ItemDataBound
Hi,
[url]http://www.windowsformsdatagridhelp.com/default.aspx?ID=3785fb7f-69ce-4089-8a35-b1ec09f63071[/url]
Ken
----------
"Nathan Sokalski" <njsokalski@hotmail.com> wrote in message
news:uQqDp8wvFHA.3548@tk2msftngp13.phx.gbl...>I want to access the DataRow used in DataBinding from the ItemDataBound
>event. In my case, the reason for doing this is to determine whether I need
>to make a word singular or plural. How can I do this? Thanks.
> --
> Nathan Sokalski
> [email]njsokalski@hotmail.com[/email]
> [url]http://www.nathansokalski.com/[/url]
>
Ken Tucker [MVP] Guest
-
Nathan Sokalski #4
Re: Accessing the current DataRow of the DataSource from ItemDataBound
This seems to work except for one thing. I get the error "Option Strict On
disallows late binding." I can obviously turn Option Strict Off, but if
possible I would like to avoid doing this. Is this possible? Thanks.
--
Nathan Sokalski
[email]njsokalski@hotmail.com[/email]
[url]http://www.nathansokalski.com/[/url]
"Adam Knight" <adam@pertrain.com.au> wrote in message
news:%23Gk6qHxvFHA.2212@TK2MSFTNGP15.phx.gbl...> Use the DataGridItems DataItem method.
> It Returns a reference to the source data row as a DataRowView object.
>
> Hope it helps.
> Adam
>
>
Nathan Sokalski Guest
-
Nathan Sokalski #5
Re: Accessing the current DataRow of the DataSource from ItemDataBound
Could you give me an example? I am using the following code:
Private Sub datRatings_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataListItemEventArgs) Handles
datRatings.ItemDataBound
If CInt(CType(e.Item.DataItem, DataRowView)("timesrated")) > 1 Then
If e.Item.ItemType = ListItemType.Item Then
CType(e.Item.FindControl("lblTimesRated1"), Label).Text &= "s"
If e.Item.ItemType = ListItemType.AlternatingItem Then
CType(e.Item.FindControl("lblTimesRated2"), Label).Text &= "s"
End If
End Sub
And am recieving the following error:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.
Source Error:
Line 140:
Line 141: Private Sub datRatings_ItemDataBound(ByVal sender As
Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles
datRatings.ItemDataBound
Line 142: If CInt(CType(e.Item.DataItem,
DataRowView)("timesrated")) > 1 Then
Line 143: If e.Item.ItemType = ListItemType.Item Then
CType(e.Item.FindControl("lblTimesRated1"), Label).Text &= "s"
Line 144: If e.Item.ItemType = ListItemType.AlternatingItem
Then CType(e.Item.FindControl("lblTimesRated2"), Label).Text &= "s"
Source File: C:\Inetpub\wwwroot\poetry\poemratings.aspx.vb Line: 142
Thanks.
--
Nathan Sokalski
[email]njsokalski@hotmail.com[/email]
[url]http://www.nathansokalski.com/[/url]
"Adam Knight" <adam@pertrain.com.au> wrote in message
news:%23Gk6qHxvFHA.2212@TK2MSFTNGP15.phx.gbl...> Use the DataGridItems DataItem method.
> It Returns a reference to the source data row as a DataRowView object.
>
> Hope it helps.
> Adam
>
>
Nathan Sokalski Guest
-
Elton Wang #6
Re: Accessing the current DataRow of the DataSource from ItemDataBound
Limiting your logic in
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem
' Process
End If
Otherwise, you might get Null Object reference error.
HTH
"Nathan Sokalski" <njsokalski@hotmail.com> wrote in message
news:OE%23kloyvFHA.2728@TK2MSFTNGP14.phx.gbl...> Could you give me an example? I am using the following code:
>
> Private Sub datRatings_ItemDataBound(ByVal sender As Object, ByVal e As
> System.Web.UI.WebControls.DataListItemEventArgs) Handles
> datRatings.ItemDataBound
>
> If CInt(CType(e.Item.DataItem, DataRowView)("timesrated")) > 1 Then
>
> If e.Item.ItemType = ListItemType.Item Then
> CType(e.Item.FindControl("lblTimesRated1"), Label).Text &= "s"
>
> If e.Item.ItemType = ListItemType.AlternatingItem Then
> CType(e.Item.FindControl("lblTimesRated2"), Label).Text &= "s"
>
> End If
>
> End Sub
>
>
> And am recieving the following error:
>
> Object reference not set to an instance of an object.
> Description: An unhandled exception occurred during the execution of the
> current web request. Please review the stack trace for more information
> about the error and where it originated in the code.
>
> Exception Details: System.NullReferenceException: Object reference not set
> to an instance of an object.
>
> Source Error:
>
> Line 140:
> Line 141: Private Sub datRatings_ItemDataBound(ByVal sender As
> Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs)
> Handles datRatings.ItemDataBound
> Line 142: If CInt(CType(e.Item.DataItem,
> DataRowView)("timesrated")) > 1 Then
> Line 143: If e.Item.ItemType = ListItemType.Item Then
> CType(e.Item.FindControl("lblTimesRated1"), Label).Text &= "s"
> Line 144: If e.Item.ItemType = ListItemType.AlternatingItem
> Then CType(e.Item.FindControl("lblTimesRated2"), Label).Text &= "s"
>
> Source File: C:\Inetpub\wwwroot\poetry\poemratings.aspx.vb Line: 142
>
>
> Thanks.
> --
> Nathan Sokalski
> [email]njsokalski@hotmail.com[/email]
> [url]http://www.nathansokalski.com/[/url]
>
> "Adam Knight" <adam@pertrain.com.au> wrote in message
> news:%23Gk6qHxvFHA.2212@TK2MSFTNGP15.phx.gbl...>>> Use the DataGridItems DataItem method.
>> It Returns a reference to the source data row as a DataRowView object.
>>
>> Hope it helps.
>> Adam
>>
>>
>
Elton Wang Guest



Reply With Quote

