Edit Item Template ... Help Please!

G

Greg

I have a datagrid control with a template column. I am trying to get
the text out of the textbox control.

The FindControl method finds the control but it always brings back ""
as the text value regardless of what I enter in the text box?


Dim strDay As String = CType(e.Item.FindControl("txtDay"),
TextBox).Text

--------------------------------------------------------------------------
Here is the full code of the event
---------------------------------------------------------------------------


Public Sub dgrdPlans_UpdateCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
dgrdPlans.UpdateCommand
Static varPlanID As Integer
Dim varRowIndex As Integer
varRowIndex = e.Item.ItemIndex

varPlanID = CInt(dgrdPlans.Items(varRowIndex).Cells(3).Text)

Dim strDay As String = CType(e.Item.FindControl("txtDay"),
TextBox).Text


Dim txtAchieveMonth As TextBox =
CType(e.Item.FindControl("txtMonth"), TextBox)
Dim strMonth As String
strMonth = txtAchieveMonth.Text

Dim txtAchieveYear As TextBox =
CType(e.Item.FindControl("txtYear"), TextBox)
Dim strYear As String
strYear = txtAchieveYear.Text


Dim dteAchieveDate As Date
'Check that there is a valid date
If IsDate(CDate(strDay & "/" & strMonth & "/" & strYear)) Then
dteAchieveDate = (CDate(strDay & "/" & strMonth & "/" &
strYear))
End If

Try
InsertActivity(varPlanID, dteAchieveDate)

Catch sqlEx As SqlException
Response.Write(sqlEx.ToString)
Catch ex As Exception
Response.Write(ex.ToString)

Finally
dgrdPlans.EditItemIndex = -1
'LoadDataGrid1()
End Try
End Sub


Thanks
Greg
 
K

kdub

If you rebind the datagrid on each form_load, regardless of IsPostback, you
will lose the values in the textbox. This MAY be your issue.

If Not Page.IsPostback Then
Me.DataGrid1.Databind
End If

Kevin
 
G

Greg White

Kevin

Thanks for the reply. You are quite correct. I am rebinding the dataset
each time the page_load event fires because I have a filter control
that builds a dataset for the page based on the selected filter values.
I did this because I am giving the user the option to print a web
report. The web report component uses a datatable as a datasource....

.. any suggestions on how I should tackle this problem?

Thanks
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top