Edit Item Template ... Help Please!

Discussion in 'ASP .Net Web Controls' started by Greg, Apr 26, 2004.

  1. Greg

    Greg Guest

    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
     
    Greg, Apr 26, 2004
    #1
    1. Advertising

  2. Greg

    kdub Guest

    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

    "Greg" <> wrote in message
    news:...
    > 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
     
    kdub, Apr 26, 2004
    #2
    1. Advertising

  3. Greg

    Greg White Guest

    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


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Greg White, Apr 27, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nevyn Twyll
    Replies:
    1
    Views:
    7,542
    S. Justin Gengo
    Aug 16, 2003
  2. =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=

    Please I need help with a datagrid item on edit

    =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=, May 19, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    546
    =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=
    May 20, 2005
  3. Adam Knight

    Edit Item Template Problem!

    Adam Knight, Aug 7, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    856
    Adam Knight
    Aug 7, 2005
  4. =?Utf-8?B?SmVyb2QgSGF0bGV5?=

    GridView add multiple controls to edit item template

    =?Utf-8?B?SmVyb2QgSGF0bGV5?=, Oct 7, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    1,101
    =?Utf-8?B?SmVyb2QgSGF0bGV5?=
    Oct 8, 2006
  5. Ann
    Replies:
    0
    Views:
    173
Loading...

Share This Page