How to read from Details view

How to read from Details view

am 02.04.2008 22:29:20 von Ed Dror

Hi there,

I'm using asp.net 2.0 vb

And I wrote this

Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles GridView1.SelectedIndexChanged
txtGNID.Text = Me.GridView1.SelectedRow.Cells(1).Text
End Sub

Every time when I slecet row my text box will show the selected cell value
(in this case is my VendorID)

Now I have a DetailsView

Protected Sub DetailsView1_PageIndexChanging(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.DetailsViewPageEventArgs) Handles
DetailsView1.PageIndexChanging

lblColorID.Text = ?

End Sub

What is the equivalent to the Grid view

I tried: lblColorID.Text = Me.DetailsView1.FindControl("ColorID").ID
but no luck

Thanks,

Ed Dror

RE: How to read from Details view

am 03.04.2008 04:45:29 von stcheng

Hi Ed,

As for the DetailsView cell reading question you mentioned, I've performed
some research on my side. Here are what I found:

** In DetailsView, when you change the page index, it will first fire the
PageIndexChanging/PageIndexChanged event, at that time, new data(row)
hasn't been bound to DetailsView. The DataBound happend after the
PageIndexChanged. Therefore, "PageIndexChanged" is not the proper place to
retrieve the new updated values from DetailsView. Instead, I suggest using
the "DataBound" event which will fire not only when changing index but also
at the initial databinding time.

** In addition, for retrieving values from DetailsView. if the field you
want to rettrieve is a key column(set as "DataKey" in DetailsView), you can
use DetailsView.DataKey.Value/Values to visit it. If it is not a key
column, you can access it through the
DetailsView.Row(index).Cells(index).Text

Here is a simple test page I used on my side which demonstrate using the
Databound event to retrieve the updated values(of the new selected record):

=========aspx ===========


ConnectionString="<%$ ConnectionStrings:testdbConnectionString %>"
DeleteCommand="DELETE FROM [persons] WHERE [id] = @id"
InsertCommand="INSERT INTO [persons] ([id], [name], [age], [title]) VALUES
(@id, @name, @age, @title)"
SelectCommand="SELECT [id], [name], [age], [title] FROM
[persons]" UpdateCommand="UPDATE [persons] SET [name] = @name, [age] =
@age, [title] = @title WHERE [id] = @id">
















AllowPaging="True" AutoGenerateRows="False"
DataKeyNames="id" DataSourceID="SqlDataSource1" Height="50px"
Width="125px">

ReadOnly="True" SortExpression="id" />
SortExpression="name" />
SortExpression="age" />
SortExpression="title" />




=-========code behind=======================


Partial Class VBNETViewPage
Inherits System.Web.UI.Page

Protected Sub DetailsView1_DataBound(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DetailsView1.DataBound

Response.Write("
DetailsView1_DataBound:")

Response.Write("
key: " & DetailsView1.DataKey.Value)
Response.Write("
name: " & DetailsView1.Rows(1).Cells(1).Text)
Response.Write("
name: " & DetailsView1.Rows(2).Cells(1).Text)
Response.Write("
name: " & DetailsView1.Rows(3).Cells(1).Text)

End Sub

Protected Sub DetailsView1_PageIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles DetailsView1.PageIndexChanged
Response.Write("
DetailsView1_PageIndexChanged:")
End Sub
End Class

============================================

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/de fault.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx .
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>From: "Ed Dror"
>Subject: How to read from Details view
>Date: Wed, 2 Apr 2008 13:29:20 -0700
>Hi there,
>
>I'm using asp.net 2.0 vb
>
>And I wrote this
>
>Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal
e
>As System.EventArgs) Handles GridView1.SelectedIndexChanged
> txtGNID.Text = Me.GridView1.SelectedRow.Cells(1).Text
> End Sub
>
>Every time when I slecet row my text box will show the selected cell value
>(in this case is my VendorID)
>
>Now I have a DetailsView
>
>Protected Sub DetailsView1_PageIndexChanging(ByVal sender As Object, ByVal
e
>As System.Web.UI.WebControls.DetailsViewPageEventArgs) Handles
>DetailsView1.PageIndexChanging
>
>lblColorID.Text = ?
>
> End Sub
>
>What is the equivalent to the Grid view
>
>I tried: lblColorID.Text = Me.DetailsView1.FindControl("ColorID").ID
>but no luck
>
>Thanks,
>
>Ed Dror
>
>
>
>

Re: How to read from Details view

am 04.04.2008 22:56:39 von Ed Dror

Steven,

I'm getting
Index was out of range. Must be non-negative and less than the size of the
collection.
Parameter name: index

for Databound event
lblColorID.Text = DetailsView1.Rows(0).Cells(1).Text

Thanks,

Ed Dror







"Steven Cheng [MSFT]" wrote in message
news:4fCEUTTlIHA.7196@TK2MSFTNGHUB02.phx.gbl...
> Hi Ed,
>
> As for the DetailsView cell reading question you mentioned, I've performed
> some research on my side. Here are what I found:
>
> ** In DetailsView, when you change the page index, it will first fire the
> PageIndexChanging/PageIndexChanged event, at that time, new data(row)
> hasn't been bound to DetailsView. The DataBound happend after the
> PageIndexChanged. Therefore, "PageIndexChanged" is not the proper place to
> retrieve the new updated values from DetailsView. Instead, I suggest using
> the "DataBound" event which will fire not only when changing index but
> also
> at the initial databinding time.
>
> ** In addition, for retrieving values from DetailsView. if the field you
> want to rettrieve is a key column(set as "DataKey" in DetailsView), you
> can
> use DetailsView.DataKey.Value/Values to visit it. If it is not a key
> column, you can access it through the
> DetailsView.Row(index).Cells(index).Text
>
> Here is a simple test page I used on my side which demonstrate using the
> Databound event to retrieve the updated values(of the new selected
> record):
>
> =========aspx ===========
>
>


> > ConnectionString="<%$ ConnectionStrings:testdbConnectionString %>"
> DeleteCommand="DELETE FROM [persons] WHERE [id] = @id"
> InsertCommand="INSERT INTO [persons] ([id], [name], [age], [title]) VALUES
> (@id, @name, @age, @title)"
> SelectCommand="SELECT [id], [name], [age], [title] FROM
> [persons]" UpdateCommand="UPDATE [persons] SET [name] = @name, [age] =
> @age, [title] = @title WHERE [id] = @id">
>
>
>

>
>
>
>
>
>

>
>
>
>
>
>

>

> > AllowPaging="True" AutoGenerateRows="False"
> DataKeyNames="id" DataSourceID="SqlDataSource1" Height="50px"
> Width="125px">
>
> > ReadOnly="True" SortExpression="id" />
> > SortExpression="name" />
> > SortExpression="age" />
> > SortExpression="title" />
>

>

>

>
> =-========code behind=======================
>
>
> Partial Class VBNETViewPage
> Inherits System.Web.UI.Page
>
> Protected Sub DetailsView1_DataBound(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles DetailsView1.DataBound
>
> Response.Write("
DetailsView1_DataBound:")
>
> Response.Write("
key: " & DetailsView1.DataKey.Value)
> Response.Write("
name: " & DetailsView1.Rows(1).Cells(1).Text)
> Response.Write("
name: " & DetailsView1.Rows(2).Cells(1).Text)
> Response.Write("
name: " & DetailsView1.Rows(3).Cells(1).Text)
>
> End Sub
>
> Protected Sub DetailsView1_PageIndexChanged(ByVal sender As Object,
> ByVal e As System.EventArgs) Handles DetailsView1.PageIndexChanged
> Response.Write("
DetailsView1_PageIndexChanged:")
> End Sub
> End Class
>
> ============================================
>
> Hope this helps.
>
> Sincerely,
>
> Steven Cheng
>
> Microsoft MSDN Online Support Lead
>
>
> Delighting our customers is our #1 priority. We welcome your comments and
> suggestions about how we can improve the support we provide to you. Please
> feel free to let my manager know what you think of the level of service
> provided. You can send feedback directly to my manager at:
> msdnmg@microsoft.com.
>
> ==================================================
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/subscriptions/managednewsgroups/de fault.aspx#notif
> ications.
>
> Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial response from the community or a Microsoft Support
> Engineer within 1 business day is acceptable. Please note that each follow
> up response may take approximately 2 business days as the support
> professional working with you may need further investigation to reach the
> most efficient resolution. The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions or complex
> project analysis and dump analysis issues. Issues of this nature are best
> handled working with a dedicated Microsoft Support Engineer by contacting
> Microsoft Customer Support Services (CSS) at
> http://msdn.microsoft.com/subscriptions/support/default.aspx .
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
> --------------------
>>From: "Ed Dror"
>>Subject: How to read from Details view
>>Date: Wed, 2 Apr 2008 13:29:20 -0700
>>Hi there,
>>
>>I'm using asp.net 2.0 vb
>>
>>And I wrote this
>>
>>Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal
> e
>>As System.EventArgs) Handles GridView1.SelectedIndexChanged
>> txtGNID.Text = Me.GridView1.SelectedRow.Cells(1).Text
>> End Sub
>>
>>Every time when I slecet row my text box will show the selected cell value
>>(in this case is my VendorID)
>>
>>Now I have a DetailsView
>>
>>Protected Sub DetailsView1_PageIndexChanging(ByVal sender As Object, ByVal
> e
>>As System.Web.UI.WebControls.DetailsViewPageEventArgs) Handles
>>DetailsView1.PageIndexChanging
>>
>>lblColorID.Text = ?
>>
>> End Sub
>>
>>What is the equivalent to the Grid view
>>
>>I tried: lblColorID.Text = Me.DetailsView1.FindControl("ColorID").ID
>>but no luck
>>
>>Thanks,
>>
>>Ed Dror
>>
>>
>>
>>
>

Re: How to read from Details view

am 07.04.2008 03:51:14 von stcheng

Hi Ed,

Since you get "Index out of range exception", it is likely that you've
referenced the wrong cell in the DetailsView. Generally, you can turn on
page output trace as below(so as to inspect the control tree structure of
all the controls on page):

<%@ Page Language="C#" Trace="true" ...%>

Also, you can post a simplified aspx page template here so that I can have
a look to see what's the structure of your Detailsview control.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/de fault.aspx#notif
ications.

This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
>From: "Ed Dror"
>References:
<4fCEUTTlIHA.7196@TK2MSFTNGHUB02.phx.gbl>
>Subject: Re: How to read from Details view
>Date: Fri, 4 Apr 2008 13:56:39 -0700

>Steven,
>
>I'm getting
>Index was out of range. Must be non-negative and less than the size of the
>collection.
>Parameter name: index
>
>for Databound event
>lblColorID.Text = DetailsView1.Rows(0).Cells(1).Text
>
>Thanks,
>
>Ed Dror
>
>
>
>
>
>
>
>"Steven Cheng [MSFT]" wrote in message
>news:4fCEUTTlIHA.7196@TK2MSFTNGHUB02.phx.gbl...
>> Hi Ed,
>>
>> As for the DetailsView cell reading question you mentioned, I've
performed
>> some research on my side. Here are what I found:
>>
>> ** In DetailsView, when you change the page index, it will first fire the
>> PageIndexChanging/PageIndexChanged event, at that time, new data(row)
>> hasn't been bound to DetailsView. The DataBound happend after the
>> PageIndexChanged. Therefore, "PageIndexChanged" is not the proper place
to
>> retrieve the new updated values from DetailsView. Instead, I suggest
using
>> the "DataBound" event which will fire not only when changing index but
>> also
>> at the initial databinding time.
>>
>> ** In addition, for retrieving values from DetailsView. if the field you
>> want to rettrieve is a key column(set as "DataKey" in DetailsView), you
>> can
>> use DetailsView.DataKey.Value/Values to visit it. If it is not a key
>> column, you can access it through the
>> DetailsView.Row(index).Cells(index).Text
>>
>> Here is a simple test page I used on my side which demonstrate using the
>> Databound event to retrieve the updated values(of the new selected
>> record):
>>
>> =========aspx ===========
>>
>>


>> >> ConnectionString="<%$ ConnectionStrings:testdbConnectionString %>"
>> DeleteCommand="DELETE FROM [persons] WHERE [id] = @id"
>> InsertCommand="INSERT INTO [persons] ([id], [name], [age], [title])
VALUES
>> (@id, @name, @age, @title)"
>> SelectCommand="SELECT [id], [name], [age], [title] FROM
>> [persons]" UpdateCommand="UPDATE [persons] SET [name] = @name, [age] =
>> @age, [title] = @title WHERE [id] = @id">
>>
>>
>>

>>
>>
>>
>>
>>
>>

>>
>>
>>
>>
>>
>>

>>

>> >> AllowPaging="True" AutoGenerateRows="False"
>> DataKeyNames="id" DataSourceID="SqlDataSource1" Height="50px"
>> Width="125px">
>>
>> >> ReadOnly="True" SortExpression="id" />
>> >> SortExpression="name" />
>> >> SortExpression="age" />
>> >> SortExpression="title" />
>>

>>

>>

>>
>> =-========code behind=======================
>>
>>
>> Partial Class VBNETViewPage
>> Inherits System.Web.UI.Page
>>
>> Protected Sub DetailsView1_DataBound(ByVal sender As Object, ByVal e
As
>> System.EventArgs) Handles DetailsView1.DataBound
>>
>> Response.Write("
DetailsView1_DataBound:")
>>
>> Response.Write("
key: " & DetailsView1.DataKey.Value)
>> Response.Write("
name: " & DetailsView1.Rows(1).Cells(1).Text)
>> Response.Write("
name: " & DetailsView1.Rows(2).Cells(1).Text)
>> Response.Write("
name: " & DetailsView1.Rows(3).Cells(1).Text)
>>
>> End Sub
>>
>> Protected Sub DetailsView1_PageIndexChanged(ByVal sender As Object,
>> ByVal e As System.EventArgs) Handles DetailsView1.PageIndexChanged
>> Response.Write("
DetailsView1_PageIndexChanged:")
>> End Sub
>> End Class
>>
>> ============================================
>>
>> Hope this helps.
>>
>> Sincerely,
>>
>> Steven Cheng
>>
>> Microsoft MSDN Online Support Lead
>>
>>
>> Delighting our customers is our #1 priority. We welcome your comments and
>> suggestions about how we can improve the support we provide to you.
Please
>> feel free to let my manager know what you think of the level of service
>> provided. You can send feedback directly to my manager at:
>> msdnmg@microsoft.com.
>>
>> ==================================================
>> Get notification to my posts through email? Please refer to
>>
http://msdn.microsoft.com/subscriptions/managednewsgroups/de fault.aspx#notif
>> ications.
>>
>> Note: The MSDN Managed Newsgroup support offering is for non-urgent
issues
>> where an initial response from the community or a Microsoft Support
>> Engineer within 1 business day is acceptable. Please note that each
follow
>> up response may take approximately 2 business days as the support
>> professional working with you may need further investigation to reach the
>> most efficient resolution. The offering is not appropriate for situations
>> that require urgent, real-time or phone-based interactions or complex
>> project analysis and dump analysis issues. Issues of this nature are best
>> handled working with a dedicated Microsoft Support Engineer by contacting
>> Microsoft Customer Support Services (CSS) at
>> http://msdn.microsoft.com/subscriptions/support/default.aspx .
>> ==================================================
>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
>> --------------------
>>>From: "Ed Dror"
>>>Subject: How to read from Details view
>>>Date: Wed, 2 Apr 2008 13:29:20 -0700
>>>Hi there,
>>>
>>>I'm using asp.net 2.0 vb
>>>
>>>And I wrote this
>>>
>>>Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object,
ByVal
>> e
>>>As System.EventArgs) Handles GridView1.SelectedIndexChanged
>>> txtGNID.Text = Me.GridView1.SelectedRow.Cells(1).Text
>>> End Sub
>>>
>>>Every time when I slecet row my text box will show the selected cell
value
>>>(in this case is my VendorID)
>>>
>>>Now I have a DetailsView
>>>
>>>Protected Sub DetailsView1_PageIndexChanging(ByVal sender As Object,
ByVal
>> e
>>>As System.Web.UI.WebControls.DetailsViewPageEventArgs) Handles
>>>DetailsView1.PageIndexChanging
>>>
>>>lblColorID.Text = ?
>>>
>>> End Sub
>>>
>>>What is the equivalent to the Grid view
>>>
>>>I tried: lblColorID.Text = Me.DetailsView1.FindControl("ColorID").ID
>>>but no luck
>>>
>>>Thanks,
>>>
>>>Ed Dror
>>>
>>>
>>>
>>>
>>
>
>
>