still problems with the gridview control!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?UGF1bA==?=

    still problems with the gridview control!

    Hi I have a gridview control with a template column that has a textbox and
    when the control is bound to the datasource the textbox is filled ok.
    I then change what is in the textbox in the gridview control and in the
    gridview_RowDat aBound event I have
    string DiscDescrip =
    Convert.ToStrin g((e.Row.Cells[5].FindControl("t xbxDiscgv") as TextBox ).Text);

    This returns what was initially loaded in the textbox but not what I had
    just changed it to, any ideas?
    Thanks Paul.


    --
    Paul G
    Software engineer.
  • bwspell@cox.net

    #2
    Re: still problems with the gridview control!

    On Jun 30, 1:45 pm, Paul <P...@discussio ns.microsoft.co mwrote:
    Hi I have a gridview control with a template column that has a textbox and
    when the control is bound to the datasource the textbox is filled ok.
    I then change what is in the textbox in the gridview control and in the
    gridview_RowDat aBound event I have
                              string DiscDescrip =
    Convert.ToStrin g((e.Row.Cells[5].FindControl("t xbxDiscgv") as TextBox ).Text);
    >
    This returns what was initially loaded in the textbox but not what I had
    just changed it to, any ideas?
    Thanks Paul.
    >
    --
    Paul G
    Software engineer.
    Have a look at the RowUpdaing event and the NewValues.

    regards,

    Big B

    Comment

    • =?Utf-8?B?UGF1bA==?=

      #3
      Re: still problems with the gridview control!

      Hi tried the following and the code is fired when the edit button is selected
      but the e.OldValues and e.NewValues is empty?
      Thanks.
      protected void gvwDiscrepancie s_RowUpdating(o bject sender,
      GridViewUpdateE ventArgs e)
      {
      string stempold = (string)e.OldVa lues[0];
      string stemp = (string)e.NewVa lues[0];
      }
      --
      Paul G
      Software engineer.


      "bwspell@cox.ne t" wrote:
      On Jun 30, 1:45 pm, Paul <P...@discussio ns.microsoft.co mwrote:
      Hi I have a gridview control with a template column that has a textbox and
      when the control is bound to the datasource the textbox is filled ok.
      I then change what is in the textbox in the gridview control and in the
      gridview_RowDat aBound event I have
      string DiscDescrip =
      Convert.ToStrin g((e.Row.Cells[5].FindControl("t xbxDiscgv") as TextBox ).Text);

      This returns what was initially loaded in the textbox but not what I had
      just changed it to, any ideas?
      Thanks Paul.

      --
      Paul G
      Software engineer.
      >
      Have a look at the RowUpdaing event and the NewValues.
      >
      regards,
      >
      Big B
      >

      Comment

      • bwspell@cox.net

        #4
        Re: still problems with the gridview control!

        On Jun 30, 2:38 pm, Paul <P...@discussio ns.microsoft.co mwrote:
        Hi tried the following and the code is fired when the edit button is selected
        but the e.OldValues and e.NewValues is empty?
        Thanks.
        protected void gvwDiscrepancie s_RowUpdating(o bject sender,
        GridViewUpdateE ventArgs e)
            {
                string stempold = (string)e.OldVa lues[0];
                string stemp = (string)e.NewVa lues[0];}
        >
        --
        Paul G
        Software engineer.
        >
        >
        >
        "bwsp...@cox.ne t" wrote:
        On Jun 30, 1:45 pm, Paul <P...@discussio ns.microsoft.co mwrote:
        Hi I have a gridview control with a template column that has a textboxand
        when the control is bound to the datasource the textbox is filled ok.
        I then change what is in the textbox in the gridview control and in the
        gridview_RowDat aBound event I have
                                  string DiscDescrip=
        Convert.ToStrin g((e.Row.Cells[5].FindControl("t xbxDiscgv") as TextBox ).Text);
        >
        This returns what was initially loaded in the textbox but not what I had
        just changed it to, any ideas?
        Thanks Paul.
        >
        --
        Paul G
        Software engineer.
        >
        Have a look at the RowUpdaing event and the NewValues.
        >
        regards,
        >
        Big B- Hide quoted text -
        >
        - Show quoted text -
        This is what I use in my code behind (VB):

        Dim gv As GridView = CType(sender,
        GridView).Namin gContainer.Find Control("GridVi ew")
        Dim key As DataKey = gv.DataKeys(0)

        Dim TripKey As Object = CType(key.Value s(0), Object)
        Dim TripMiles As Integer = CType(key.Value s(2).ToString,
        Integer)
        Dim TripPCode As String = key.Values(5).T oString().Trim
        Dim TripFCode As String = key.Values(6).T oString().Trim
        Dim TripDate As Date = CType(key.Value s(1).ToString, Date)
        Dim BeginMiles As Integer = CType(key.Value s(3).ToString,
        Integer)
        Dim EndMiles As Integer = CType(key.Value s(4).ToString,
        Integer)
        Dim TripSubCode As String = key.Values(7).T oString().Trim

        TripPCode = e.NewValues("Pr ojectSubCode"). ToString().Trim

        e.OldValues("Tr ipID") = TripKey
        e.OldValues("Tr ipMiles") = TripMiles
        e.OldValues("Pr ojectSubCode") = TripPCode
        e.OldValues("Tr ipDate") = TripDate
        e.OldValues("Fu ndsSourceCode") = TripFCode
        e.OldValues("Be ginMileage") = BeginMiles
        e.OldValues("En dMileage") = EndMiles
        e.OldValues("Su bProject") = TripSubCode

        For i = 0 To e.NewValues.Cou nt - 1

        If e.NewValues.Ite m(i) = Nothing Then

        Select Case i
        Case 0
        e.NewValues.Ite m(i) = TripKey
        Case 1
        e.NewValues.Ite m(i) = TripMiles
        Case 2
        e.NewValues.Ite m(i) = TripDate
        Case 3
        e.NewValues.Ite m(i) = BeginMiles
        Case 4
        e.NewValues.Ite m(i) = EndMiles

        End Select

        End If

        Next

        e.NewValues("Pr ojectSubCode") =
        CType(gv.Rows(e .RowIndex).Find Control("ddlPro j"),
        DropDownList).S electedValue
        e.NewValues("Fu ndsSourceCode") =
        CType(gv.Rows(e .RowIndex).Find Control("ddlFun ds"),
        DropDownList).S electedValue
        e.NewValues("Su bproject") =
        CType(gv.Rows(e .RowIndex).Find Control("ddlSub "),
        DropDownList).S electedValue

        sSubProject = CType(gv.Rows(e .RowIndex).Find Control("ddlSub "),
        DropDownList).S electedValue

        TripFCode = e.NewValues("Fu ndsSourceCode") .ToString().Tri m
        BeginMiles = e.NewValues("Be ginMileage").To String()
        EndMileage = e.NewValues("En dMileage").ToSt ring()
        TripSubCode = sSubProject
        TripMiles = e.NewValues("Tr ipTotal").ToStr ing
        TripPCode = e.NewValues("Pr ojectSubCode"). ToString().Trim
        TripDate = CType(e.NewValu es("TripDate"). ToString(), DateTime)

        I then use the variables to update my datasource.

        Do you have Datakeys setup?

        regards,

        Big B

        Comment

        • =?Utf-8?B?UGF1bA==?=

          #5
          Re: still problems with the gridview control!

          thanks for the response. I was able to set up a datakey and then able to get
          the data ok. It looks like they want to be able to make changes to several
          rows on the grid and then hit a single button to save all the rows. I have a
          save button but do not think there is any way to access the new gridview data
          in the save button click event. I also tried to save the data in the
          RowDataBound event but the data from the gridview does not capture any newly
          entered data, just the old data. Thinking I may need to use a table instead
          of the gridview.
          --
          Paul G
          Software engineer.


          "bwspell@cox.ne t" wrote:
          On Jun 30, 2:38 pm, Paul <P...@discussio ns.microsoft.co mwrote:
          Hi tried the following and the code is fired when the edit button is selected
          but the e.OldValues and e.NewValues is empty?
          Thanks.
          protected void gvwDiscrepancie s_RowUpdating(o bject sender,
          GridViewUpdateE ventArgs e)
          {
          string stempold = (string)e.OldVa lues[0];
          string stemp = (string)e.NewVa lues[0];}

          --
          Paul G
          Software engineer.



          "bwsp...@cox.ne t" wrote:
          On Jun 30, 1:45 pm, Paul <P...@discussio ns.microsoft.co mwrote:
          Hi I have a gridview control with a template column that has a textbox and
          when the control is bound to the datasource the textbox is filled ok.
          I then change what is in the textbox in the gridview control and in the
          gridview_RowDat aBound event I have
          string DiscDescrip =
          Convert.ToStrin g((e.Row.Cells[5].FindControl("t xbxDiscgv") as TextBox ).Text);
          This returns what was initially loaded in the textbox but not what I had
          just changed it to, any ideas?
          Thanks Paul.
          --
          Paul G
          Software engineer.
          Have a look at the RowUpdaing event and the NewValues.
          regards,
          Big B- Hide quoted text -
          - Show quoted text -
          >
          This is what I use in my code behind (VB):
          >
          Dim gv As GridView = CType(sender,
          GridView).Namin gContainer.Find Control("GridVi ew")
          Dim key As DataKey = gv.DataKeys(0)
          >
          Dim TripKey As Object = CType(key.Value s(0), Object)
          Dim TripMiles As Integer = CType(key.Value s(2).ToString,
          Integer)
          Dim TripPCode As String = key.Values(5).T oString().Trim
          Dim TripFCode As String = key.Values(6).T oString().Trim
          Dim TripDate As Date = CType(key.Value s(1).ToString, Date)
          Dim BeginMiles As Integer = CType(key.Value s(3).ToString,
          Integer)
          Dim EndMiles As Integer = CType(key.Value s(4).ToString,
          Integer)
          Dim TripSubCode As String = key.Values(7).T oString().Trim
          >
          TripPCode = e.NewValues("Pr ojectSubCode"). ToString().Trim
          >
          e.OldValues("Tr ipID") = TripKey
          e.OldValues("Tr ipMiles") = TripMiles
          e.OldValues("Pr ojectSubCode") = TripPCode
          e.OldValues("Tr ipDate") = TripDate
          e.OldValues("Fu ndsSourceCode") = TripFCode
          e.OldValues("Be ginMileage") = BeginMiles
          e.OldValues("En dMileage") = EndMiles
          e.OldValues("Su bProject") = TripSubCode
          >
          For i = 0 To e.NewValues.Cou nt - 1
          >
          If e.NewValues.Ite m(i) = Nothing Then
          >
          Select Case i
          Case 0
          e.NewValues.Ite m(i) = TripKey
          Case 1
          e.NewValues.Ite m(i) = TripMiles
          Case 2
          e.NewValues.Ite m(i) = TripDate
          Case 3
          e.NewValues.Ite m(i) = BeginMiles
          Case 4
          e.NewValues.Ite m(i) = EndMiles
          >
          End Select
          >
          End If
          >
          Next
          >
          e.NewValues("Pr ojectSubCode") =
          CType(gv.Rows(e .RowIndex).Find Control("ddlPro j"),
          DropDownList).S electedValue
          e.NewValues("Fu ndsSourceCode") =
          CType(gv.Rows(e .RowIndex).Find Control("ddlFun ds"),
          DropDownList).S electedValue
          e.NewValues("Su bproject") =
          CType(gv.Rows(e .RowIndex).Find Control("ddlSub "),
          DropDownList).S electedValue
          >
          sSubProject = CType(gv.Rows(e .RowIndex).Find Control("ddlSub "),
          DropDownList).S electedValue
          >
          TripFCode = e.NewValues("Fu ndsSourceCode") .ToString().Tri m
          BeginMiles = e.NewValues("Be ginMileage").To String()
          EndMileage = e.NewValues("En dMileage").ToSt ring()
          TripSubCode = sSubProject
          TripMiles = e.NewValues("Tr ipTotal").ToStr ing
          TripPCode = e.NewValues("Pr ojectSubCode"). ToString().Trim
          TripDate = CType(e.NewValu es("TripDate"). ToString(), DateTime)
          >
          I then use the variables to update my datasource.
          >
          Do you have Datakeys setup?
          >
          regards,
          >
          Big B
          >

          Comment

          • bwspell@cox.net

            #6
            Re: still problems with the gridview control!

            On Jul 1, 9:15 am, Paul <P...@discussio ns.microsoft.co mwrote:
            thanks for the response.  I was able to set up a datakey and then able to get
            the data ok.  It looks like they want to be able to make changes to several
            rows on the grid and then hit a single button to save all the rows.  I have a
            save button but do not think there is any way to access the new gridview data
            in the save button click event.  I also tried to save the data in the
            RowDataBound event but the data from the gridview does not capture any newly
            entered data, just the old data.  Thinking I may need to use a table instead
            of the gridview.
            --
            Paul G
            Software engineer.
            >
            >
            >
            "bwsp...@cox.ne t" wrote:
            On Jun 30, 2:38 pm, Paul <P...@discussio ns.microsoft.co mwrote:
            Hi tried the following and the code is fired when the edit button is selected
            but the e.OldValues and e.NewValues is empty?
            Thanks.
            protected void gvwDiscrepancie s_RowUpdating(o bject sender,
            GridViewUpdateE ventArgs e)
                {
                    string stempold = (string)e.OldVa lues[0];
                    string stemp = (string)e.NewVa lues[0];}
            >
            --
            Paul G
            Software engineer.
            >
            "bwsp...@cox.ne t" wrote:
            On Jun 30, 1:45 pm, Paul <P...@discussio ns.microsoft.co mwrote:
            Hi I have a gridview control with a template column that has a textbox and
            when the control is bound to the datasource the textbox is filledok.
            I then change what is in the textbox in the gridview control and in the
            gridview_RowDat aBound event I have
                                      string DiscDescrip =
            Convert.ToStrin g((e.Row.Cells[5].FindControl("t xbxDiscgv") as TextBox ).Text);
            >
            This returns what was initially loaded in the textbox but not what I had
            just changed it to, any ideas?
            Thanks Paul.
            >
            --
            Paul G
            Software engineer.
            >
            Have a look at the RowUpdaing event and the NewValues.
            >
            regards,
            >
            Big B- Hide quoted text -
            >
            - Show quoted text -
            >
            This is what I use in my code behind (VB):
            >
                    Dim gv As GridView = CType(sender,
            GridView).Namin gContainer.Find Control("GridVi ew")
                    Dim key As DataKey = gv.DataKeys(0)
            >
                    Dim TripKey As Object = CType(key.Value s(0), Object)
                    Dim TripMiles As Integer = CType(key.Value s(2).ToString,
            Integer)
                    Dim TripPCode As String = key.Values(5).T oString().Trim
                    Dim TripFCode As String = key.Values(6).T oString().Trim
                    Dim TripDate As Date = CType(key.Value s(1).ToString, Date)
                    Dim BeginMiles As Integer = CType(key.Value s(3).ToString,
            Integer)
                    Dim EndMiles As Integer = CType(key.Value s(4).ToString,
            Integer)
                    Dim TripSubCode As String = key.Values(7).T oString().Trim
            >
                    TripPCode = e.NewValues("Pr ojectSubCode"). ToString().Trim
            >
                    e.OldValues("Tr ipID") = TripKey
                    e.OldValues("Tr ipMiles") = TripMiles
                    e.OldValues("Pr ojectSubCode") = TripPCode
                    e.OldValues("Tr ipDate") = TripDate
                    e.OldValues("Fu ndsSourceCode") = TripFCode
                    e.OldValues("Be ginMileage") = BeginMiles
                    e.OldValues("En dMileage") = EndMiles
                    e.OldValues("Su bProject") = TripSubCode
            >
                    For i = 0 To e.NewValues.Cou nt - 1
            >
                        If e.NewValues.Ite m(i) = Nothing Then
            >
                            Select Case i
                                Case 0
                                    e.NewValues.Ite m(i) =TripKey
                                Case 1
                                    e.NewValues.Ite m(i) =TripMiles
                                Case 2
                                    e.NewValues.Ite m(i) =TripDate
                                Case 3
                                    e.NewValues.Ite m(i) =BeginMiles
                                Case 4
                                    e.NewValues.Ite m(i) =EndMiles
            >
                            End Select
            >
                        End If
            >
                    Next
            >
                    e.NewValues("Pr ojectSubCode") =
            CType(gv.Rows(e .RowIndex).Find Control("ddlPro j"),
            DropDownList).S electedValue
                    e.NewValues("Fu ndsSourceCode") =
            CType(gv.Rows(e .RowIndex).Find Control("ddlFun ds"),
            DropDownList).S electedValue
                    e.NewValues("Su bproject") =
            CType(gv.Rows(e .RowIndex).Find Control("ddlSub "),
            DropDownList).S electedValue
            >
                    sSubProject = CType(gv.Rows(e .RowIndex).Find Control("ddlSub "),
            DropDownList).S electedValue
            >
                    TripFCode = e.NewValues("Fu ndsSourceCode") .ToString()..Tr im
                    BeginMiles = e.NewValues("Be ginMileage").To String()
                    EndMileage = e.NewValues("En dMileage").ToSt ring()
                    TripSubCode = sSubProject
                    TripMiles = e.NewValues("Tr ipTotal").ToStr ing
                    TripPCode = e.NewValues("Pr ojectSubCode"). ToString().Trim
                    TripDate = CType(e.NewValu es("TripDate"). ToString(), DateTime)
            >
            I then use the variables to update my datasource.
            >
            Do you have Datakeys setup?
            >
            regards,
            >
            Big B- Hide quoted text -
            >
            - Show quoted text -
            The only way I've done it is a row at a time.
            Do a Google on Gridview, I recall seeing an example of editing a
            gridview and saving all changes at once with a button.
            Could have been @ 4Guysfromrolla site.
            Good luck.

            regards,

            Big B

            Comment

            • =?Utf-8?B?UGF1bA==?=

              #7
              Re: still problems with the gridview control!

              Hi I found an example that looks like it will work in the click button event,
              thanks!
              --
              Paul G
              Software engineer.


              "bwspell@cox.ne t" wrote:
              On Jul 1, 9:15 am, Paul <P...@discussio ns.microsoft.co mwrote:
              thanks for the response. I was able to set up a datakey and then able to get
              the data ok. It looks like they want to be able to make changes to several
              rows on the grid and then hit a single button to save all the rows. I have a
              save button but do not think there is any way to access the new gridview data
              in the save button click event. I also tried to save the data in the
              RowDataBound event but the data from the gridview does not capture any newly
              entered data, just the old data. Thinking I may need to use a table instead
              of the gridview.
              --
              Paul G
              Software engineer.



              "bwsp...@cox.ne t" wrote:
              On Jun 30, 2:38 pm, Paul <P...@discussio ns.microsoft.co mwrote:
              Hi tried the following and the code is fired when the edit button is selected
              but the e.OldValues and e.NewValues is empty?
              Thanks.
              protected void gvwDiscrepancie s_RowUpdating(o bject sender,
              GridViewUpdateE ventArgs e)
              {
              string stempold = (string)e.OldVa lues[0];
              string stemp = (string)e.NewVa lues[0];}
              --
              Paul G
              Software engineer.
              "bwsp...@cox.ne t" wrote:
              On Jun 30, 1:45 pm, Paul <P...@discussio ns.microsoft.co mwrote:
              Hi I have a gridview control with a template column that has a textbox and
              when the control is bound to the datasource the textbox is filled ok.
              I then change what is in the textbox in the gridview control and in the
              gridview_RowDat aBound event I have
              string DiscDescrip =
              Convert.ToStrin g((e.Row.Cells[5].FindControl("t xbxDiscgv") as TextBox ).Text);
              This returns what was initially loaded in the textbox but not what I had
              just changed it to, any ideas?
              Thanks Paul.
              --
              Paul G
              Software engineer.
              Have a look at the RowUpdaing event and the NewValues.
              regards,
              Big B- Hide quoted text -
              - Show quoted text -
              This is what I use in my code behind (VB):
              Dim gv As GridView = CType(sender,
              GridView).Namin gContainer.Find Control("GridVi ew")
              Dim key As DataKey = gv.DataKeys(0)
              Dim TripKey As Object = CType(key.Value s(0), Object)
              Dim TripMiles As Integer = CType(key.Value s(2).ToString,
              Integer)
              Dim TripPCode As String = key.Values(5).T oString().Trim
              Dim TripFCode As String = key.Values(6).T oString().Trim
              Dim TripDate As Date = CType(key.Value s(1).ToString, Date)
              Dim BeginMiles As Integer = CType(key.Value s(3).ToString,
              Integer)
              Dim EndMiles As Integer = CType(key.Value s(4).ToString,
              Integer)
              Dim TripSubCode As String = key.Values(7).T oString().Trim
              TripPCode = e.NewValues("Pr ojectSubCode"). ToString().Trim
              e.OldValues("Tr ipID") = TripKey
              e.OldValues("Tr ipMiles") = TripMiles
              e.OldValues("Pr ojectSubCode") = TripPCode
              e.OldValues("Tr ipDate") = TripDate
              e.OldValues("Fu ndsSourceCode") = TripFCode
              e.OldValues("Be ginMileage") = BeginMiles
              e.OldValues("En dMileage") = EndMiles
              e.OldValues("Su bProject") = TripSubCode
              For i = 0 To e.NewValues.Cou nt - 1
              If e.NewValues.Ite m(i) = Nothing Then
              Select Case i
              Case 0
              e.NewValues.Ite m(i) = TripKey
              Case 1
              e.NewValues.Ite m(i) = TripMiles
              Case 2
              e.NewValues.Ite m(i) = TripDate
              Case 3
              e.NewValues.Ite m(i) = BeginMiles
              Case 4
              e.NewValues.Ite m(i) = EndMiles
              End Select
              End If
              Next
              e.NewValues("Pr ojectSubCode") =
              CType(gv.Rows(e .RowIndex).Find Control("ddlPro j"),
              DropDownList).S electedValue
              e.NewValues("Fu ndsSourceCode") =
              CType(gv.Rows(e .RowIndex).Find Control("ddlFun ds"),
              DropDownList).S electedValue
              e.NewValues("Su bproject") =
              CType(gv.Rows(e .RowIndex).Find Control("ddlSub "),
              DropDownList).S electedValue
              sSubProject = CType(gv.Rows(e .RowIndex).Find Control("ddlSub "),
              DropDownList).S electedValue
              TripFCode = e.NewValues("Fu ndsSourceCode") .ToString()..Tr im
              BeginMiles = e.NewValues("Be ginMileage").To String()
              EndMileage = e.NewValues("En dMileage").ToSt ring()
              TripSubCode = sSubProject
              TripMiles = e.NewValues("Tr ipTotal").ToStr ing
              TripPCode = e.NewValues("Pr ojectSubCode"). ToString().Trim
              TripDate = CType(e.NewValu es("TripDate"). ToString(), DateTime)
              I then use the variables to update my datasource.
              Do you have Datakeys setup?
              regards,
              Big B- Hide quoted text -
              - Show quoted text -
              >
              The only way I've done it is a row at a time.
              Do a Google on Gridview, I recall seeing an example of editing a
              gridview and saving all changes at once with a button.
              Could have been @ 4Guysfromrolla site.
              Good luck.
              >
              regards,
              >
              Big B
              >

              Comment

              Working...