How can I access a datagrid control during Edit event?

S

Stan

This is how I access Pieces field in my editable datargid during Update
event:

protected void grdMain_OnUpdate(Object sender, DataGridCommandEventArgs e)
{
string Pieces = ((TextBox) e.Item.FindControl ("txtPieces")).Text;
....
}


I need to highlight this field when user clicks Edit. (This makes easier for
them to overwrite the content of the field). However, the same code does not
work during
Edit event - FindControl returns null. It looks like the the control is not
available at this time...


Is there a way for me to access it AFTER user clicked Edit but BEFORE
Update?

Thanks,

-Stan
 
Y

Yan-Hong Huang[MSFT]

Hello Stan,

DataGrid dgTemp = ((DataGrid)sender);
if(dgTemp.EditItemIndex == e.Item.ItemIndex)
{
if(e.Item.ItemType.ToString() != "Header" && e.Item.ItemType.ToString() != "Footer")
{
DropDownList ddlTemp = ((DropDownList)e.Item.FindControl("myDDL"));
ddlTemp.Items.FindByText("myLookupValue").Selected=true;
}
}

This code could probably be simplified further, but it should be a good starting point.

HTH.

Best regards,
yhhuang
VS.NET, Visual C++
Microsoft

This posting is provided "AS IS" with no warranties, and confers no rights.
Got .Net? http://www.gotdotnet.com
--------------------
!From: "Stan" <[email protected]>
!Subject: How can I access a datagrid control during Edit event?
!Date: Thu, 10 Jul 2003 11:20:22 -0400
!Lines: 25
!X-Priority: 3
!X-MSMail-Priority: Normal
!X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
!X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
!Message-ID: <#[email protected]>
!Newsgroups: microsoft.public.dotnet.framework.aspnet
!NNTP-Posting-Host: 12.148.36.131
!Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
!Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:158335
!X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
!
!This is how I access Pieces field in my editable datargid during Update
!event:
!
!protected void grdMain_OnUpdate(Object sender, DataGridCommandEventArgs e)
!{
! string Pieces = ((TextBox) e.Item.FindControl ("txtPieces")).Text;
! ....
!}
!
!
!I need to highlight this field when user clicks Edit. (This makes easier for
!them to overwrite the content of the field). However, the same code does not
!work during
!Edit event - FindControl returns null. It looks like the the control is not
!available at this time...
!
!
!Is there a way for me to access it AFTER user clicked Edit but BEFORE
!Update?
!
!Thanks,
!
!-Stan
!
!
!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top