Hi Sck10,
Welcome to ASPNET newsgroup.
As for the Accessing TextBoxes of BoundFields in DetailsView when turning
from readonly mode to editing mode, here are some of my suggestions:
For DetailsView, the boundField create the TextBox before it finally
construct the control hierarchy and render out. So at the DetailsView's
ModeChanged event, the TextBoxes (if in edit mode) has not been created ,
we can not access them at that time. IMO, if you do need to access the
Textboxes of boundfield in edit mode, you can consider registering the
DetailsView's PreRender event, at that time the TextBoxes has been created
(if exists ). For example, here is some code snippet which get the
reference to TextBoxes of bound fields when DetailsView turn into Edit mode:
===============
protected void DetailsView1_PreRender(object sender, EventArgs e)
{
if (DetailsView1.CurrentMode == DetailsViewMode.Edit)
{
foreach (DetailsViewRow dvr in DetailsView1.Rows)
{
if (dvr.Cells.Count == 2)
{
Response.Write("<br>" + dvr.Cells[1].Text);
if(dvr.Cells[1].Controls.Count>0)
//this should be the textbox control
Response.Write("<br>" + dvr.Cells[1].Controls[0]);
}
}
}
}
===============
In addition, for get a clear view of the DetailsView's runtime control
structure, you can trun on the asp.net page's Trace so as to view the
control Tree structure which is very helpful. e.g:
<%@ Page Language="C#" AutoEventWireup="true" Trace="true"
Hope helps. Thank you!
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "sck10" <
[email protected]>
| Subject: Set value in DetailsView edit mode (.net 2)
| Date: Wed, 2 Nov 2005 10:57:29 -0600
| Lines: 21
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1506
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506
| Message-ID: <#
[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 189.202.185.135.in-addr.arpa 135.185.202.189
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:135550
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hello,
|
| I am trying to change a value when a user goes into edit mode on a
| DetailsView control. I am trying to use the following, but can not figure
| out how to get to the bound field ("MyBoundField") to set its new value.
| Any help with this would be appreciated.
|
| Sub EmployeeDetailView_ModeChanged(ByVal sender As Object, ByVal e As
| EventArgs)
| Select Case CustomerDetailView.CurrentMode
| Case DetailsViewMode.Edit
| MyBoundField.value = "some value"
| End Select
| End Sub
|
| --
| Thanks in advance,
|
| sck10
|
|
|