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 ===========
<div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
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">
<DeleteParameters>
<asp
arameter Name="id" Type="Int64" />
</DeleteParameters>
<UpdateParameters>
<asp
arameter Name="name" Type="String" />
<asp
arameter Name="age" Type="Int16" />
<asp
arameter Name="title" Type="String" />
<asp
arameter Name="id" Type="Int64" />
</UpdateParameters>
<InsertParameters>
<asp
arameter Name="id" Type="Int64" />
<asp
arameter Name="name" Type="String" />
<asp
arameter Name="age" Type="Int16" />
<asp
arameter Name="title" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
<asp
etailsView ID="DetailsView1" runat="server"
AllowPaging="True" AutoGenerateRows="False"
DataKeyNames="id" DataSourceID="SqlDataSource1" Height="50px"
Width="125px">
<Fields>
<asp:BoundField DataField="id" HeaderText="id"
ReadOnly="True" SortExpression="id" />
<asp:BoundField DataField="name" HeaderText="name"
SortExpression="name" />
<asp:BoundField DataField="age" HeaderText="age"
SortExpression="age" />
<asp:BoundField DataField="title" HeaderText="title"
SortExpression="title" />
</Fields>
</asp
etailsView>
</div>
=-========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("<br/>DetailsView1_DataBound:")
Response.Write("<br/>key: " & DetailsView1.DataKey.Value)
Response.Write("<br/>name: " & DetailsView1.Rows(1).Cells(1).Text)
Response.Write("<br/>name: " & DetailsView1.Rows(2).Cells(1).Text)
Response.Write("<br/>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("<br/>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:
(e-mail address removed).
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.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" <
[email protected]>
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