still problems with the gridview control!

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

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_RowDataBound event I have
string DiscDescrip =
Convert.ToString((e.Row.Cells[5].FindControl("txbxDiscgv") 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.
 
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_RowDataBound event I have
                          string DiscDescrip =
Convert.ToString((e.Row.Cells[5].FindControl("txbxDiscgv") 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.

Have a look at the RowUpdaing event and the NewValues.

regards,

Big B
 
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 gvwDiscrepancies_RowUpdating(object sender,
GridViewUpdateEventArgs e)
{
string stempold = (string)e.OldValues[0];
string stemp = (string)e.NewValues[0];
}
--
Paul G
Software engineer.


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_RowDataBound event I have
string DiscDescrip =
Convert.ToString((e.Row.Cells[5].FindControl("txbxDiscgv") 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.

Have a look at the RowUpdaing event and the NewValues.

regards,

Big B
 
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 gvwDiscrepancies_RowUpdating(object sender,
GridViewUpdateEventArgs e)
    {
        string stempold = (string)e.OldValues[0];
        string stemp = (string)e.NewValues[0];}

--
Paul G
Software engineer.



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_RowDataBound event I have
                          string DiscDescrip=
Convert.ToString((e.Row.Cells[5].FindControl("txbxDiscgv") 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.
Have a look at the RowUpdaing event and the NewValues.

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).NamingContainer.FindControl("GridView")
Dim key As DataKey = gv.DataKeys(0)

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

TripPCode = e.NewValues("ProjectSubCode").ToString().Trim

e.OldValues("TripID") = TripKey
e.OldValues("TripMiles") = TripMiles
e.OldValues("ProjectSubCode") = TripPCode
e.OldValues("TripDate") = TripDate
e.OldValues("FundsSourceCode") = TripFCode
e.OldValues("BeginMileage") = BeginMiles
e.OldValues("EndMileage") = EndMiles
e.OldValues("SubProject") = TripSubCode

For i = 0 To e.NewValues.Count - 1

If e.NewValues.Item(i) = Nothing Then

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

End Select

End If

Next

e.NewValues("ProjectSubCode") =
CType(gv.Rows(e.RowIndex).FindControl("ddlProj"),
DropDownList).SelectedValue
e.NewValues("FundsSourceCode") =
CType(gv.Rows(e.RowIndex).FindControl("ddlFunds"),
DropDownList).SelectedValue
e.NewValues("Subproject") =
CType(gv.Rows(e.RowIndex).FindControl("ddlSub"),
DropDownList).SelectedValue

sSubProject = CType(gv.Rows(e.RowIndex).FindControl("ddlSub"),
DropDownList).SelectedValue

TripFCode = e.NewValues("FundsSourceCode").ToString().Trim
BeginMiles = e.NewValues("BeginMileage").ToString()
EndMileage = e.NewValues("EndMileage").ToString()
TripSubCode = sSubProject
TripMiles = e.NewValues("TripTotal").ToString
TripPCode = e.NewValues("ProjectSubCode").ToString().Trim
TripDate = CType(e.NewValues("TripDate").ToString(), DateTime)

I then use the variables to update my datasource.

Do you have Datakeys setup?

regards,

Big B
 
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.


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 gvwDiscrepancies_RowUpdating(object sender,
GridViewUpdateEventArgs e)
{
string stempold = (string)e.OldValues[0];
string stemp = (string)e.NewValues[0];}

--
Paul G
Software engineer.



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_RowDataBound event I have
string DiscDescrip =
Convert.ToString((e.Row.Cells[5].FindControl("txbxDiscgv") 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.
Have a look at the RowUpdaing event and the NewValues.

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).NamingContainer.FindControl("GridView")
Dim key As DataKey = gv.DataKeys(0)

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

TripPCode = e.NewValues("ProjectSubCode").ToString().Trim

e.OldValues("TripID") = TripKey
e.OldValues("TripMiles") = TripMiles
e.OldValues("ProjectSubCode") = TripPCode
e.OldValues("TripDate") = TripDate
e.OldValues("FundsSourceCode") = TripFCode
e.OldValues("BeginMileage") = BeginMiles
e.OldValues("EndMileage") = EndMiles
e.OldValues("SubProject") = TripSubCode

For i = 0 To e.NewValues.Count - 1

If e.NewValues.Item(i) = Nothing Then

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

End Select

End If

Next

e.NewValues("ProjectSubCode") =
CType(gv.Rows(e.RowIndex).FindControl("ddlProj"),
DropDownList).SelectedValue
e.NewValues("FundsSourceCode") =
CType(gv.Rows(e.RowIndex).FindControl("ddlFunds"),
DropDownList).SelectedValue
e.NewValues("Subproject") =
CType(gv.Rows(e.RowIndex).FindControl("ddlSub"),
DropDownList).SelectedValue

sSubProject = CType(gv.Rows(e.RowIndex).FindControl("ddlSub"),
DropDownList).SelectedValue

TripFCode = e.NewValues("FundsSourceCode").ToString().Trim
BeginMiles = e.NewValues("BeginMileage").ToString()
EndMileage = e.NewValues("EndMileage").ToString()
TripSubCode = sSubProject
TripMiles = e.NewValues("TripTotal").ToString
TripPCode = e.NewValues("ProjectSubCode").ToString().Trim
TripDate = CType(e.NewValues("TripDate").ToString(), DateTime)

I then use the variables to update my datasource.

Do you have Datakeys setup?

regards,

Big B
 
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.



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 gvwDiscrepancies_RowUpdating(object sender,
GridViewUpdateEventArgs e)
    {
        string stempold = (string)e.OldValues[0];
        string stemp = (string)e.NewValues[0];}
--
Paul G
Software engineer.
:
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_RowDataBound event I have
                          string DiscDescrip =
Convert.ToString((e.Row.Cells[5].FindControl("txbxDiscgv") 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).NamingContainer.FindControl("GridView")
        Dim key As DataKey = gv.DataKeys(0)
        Dim TripKey As Object = CType(key.Values(0), Object)
        Dim TripMiles As Integer = CType(key.Values(2).ToString,
Integer)
        Dim TripPCode As String = key.Values(5).ToString().Trim
        Dim TripFCode As String = key.Values(6).ToString().Trim
        Dim TripDate As Date = CType(key.Values(1).ToString, Date)
        Dim BeginMiles As Integer = CType(key.Values(3).ToString,
Integer)
        Dim EndMiles As Integer = CType(key.Values(4).ToString,
Integer)
        Dim TripSubCode As String = key.Values(7).ToString().Trim
        TripPCode = e.NewValues("ProjectSubCode").ToString().Trim
        e.OldValues("TripID") = TripKey
        e.OldValues("TripMiles") = TripMiles
        e.OldValues("ProjectSubCode") = TripPCode
        e.OldValues("TripDate") = TripDate
        e.OldValues("FundsSourceCode") = TripFCode
        e.OldValues("BeginMileage") = BeginMiles
        e.OldValues("EndMileage") = EndMiles
        e.OldValues("SubProject") = TripSubCode
        For i = 0 To e.NewValues.Count - 1
            If e.NewValues.Item(i) = Nothing Then
                Select Case i
                    Case 0
                        e.NewValues.Item(i) =TripKey
                    Case 1
                        e.NewValues.Item(i) =TripMiles
                    Case 2
                        e.NewValues.Item(i) =TripDate
                    Case 3
                        e.NewValues.Item(i) =BeginMiles
                    Case 4
                        e.NewValues.Item(i) =EndMiles
                End Select
            End If
        Next
        e.NewValues("ProjectSubCode") =
CType(gv.Rows(e.RowIndex).FindControl("ddlProj"),
DropDownList).SelectedValue
        e.NewValues("FundsSourceCode") =
CType(gv.Rows(e.RowIndex).FindControl("ddlFunds"),
DropDownList).SelectedValue
        e.NewValues("Subproject") =
CType(gv.Rows(e.RowIndex).FindControl("ddlSub"),
DropDownList).SelectedValue
        sSubProject = CType(gv.Rows(e.RowIndex).FindControl("ddlSub"),
DropDownList).SelectedValue
        TripFCode = e.NewValues("FundsSourceCode").ToString()..Trim
        BeginMiles = e.NewValues("BeginMileage").ToString()
        EndMileage = e.NewValues("EndMileage").ToString()
        TripSubCode = sSubProject
        TripMiles = e.NewValues("TripTotal").ToString
        TripPCode = e.NewValues("ProjectSubCode").ToString().Trim
        TripDate = CType(e.NewValues("TripDate").ToString(), DateTime)
I then use the variables to update my datasource.
Do you have Datakeys setup?

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
 
Hi I found an example that looks like it will work in the click button event,
thanks!
--
Paul G
Software engineer.


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.



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 gvwDiscrepancies_RowUpdating(object sender,
GridViewUpdateEventArgs e)
{
string stempold = (string)e.OldValues[0];
string stemp = (string)e.NewValues[0];}
:
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_RowDataBound event I have
string DiscDescrip =
Convert.ToString((e.Row.Cells[5].FindControl("txbxDiscgv") 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.
Have a look at the RowUpdaing event and the NewValues.

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).NamingContainer.FindControl("GridView")
Dim key As DataKey = gv.DataKeys(0)
Dim TripKey As Object = CType(key.Values(0), Object)
Dim TripMiles As Integer = CType(key.Values(2).ToString,
Integer)
Dim TripPCode As String = key.Values(5).ToString().Trim
Dim TripFCode As String = key.Values(6).ToString().Trim
Dim TripDate As Date = CType(key.Values(1).ToString, Date)
Dim BeginMiles As Integer = CType(key.Values(3).ToString,
Integer)
Dim EndMiles As Integer = CType(key.Values(4).ToString,
Integer)
Dim TripSubCode As String = key.Values(7).ToString().Trim
TripPCode = e.NewValues("ProjectSubCode").ToString().Trim
e.OldValues("TripID") = TripKey
e.OldValues("TripMiles") = TripMiles
e.OldValues("ProjectSubCode") = TripPCode
e.OldValues("TripDate") = TripDate
e.OldValues("FundsSourceCode") = TripFCode
e.OldValues("BeginMileage") = BeginMiles
e.OldValues("EndMileage") = EndMiles
e.OldValues("SubProject") = TripSubCode
For i = 0 To e.NewValues.Count - 1
If e.NewValues.Item(i) = Nothing Then
Select Case i
Case 0
e.NewValues.Item(i) = TripKey
Case 1
e.NewValues.Item(i) = TripMiles
Case 2
e.NewValues.Item(i) = TripDate
Case 3
e.NewValues.Item(i) = BeginMiles
Case 4
e.NewValues.Item(i) = EndMiles
End Select
End If

e.NewValues("ProjectSubCode") =
CType(gv.Rows(e.RowIndex).FindControl("ddlProj"),
DropDownList).SelectedValue
e.NewValues("FundsSourceCode") =
CType(gv.Rows(e.RowIndex).FindControl("ddlFunds"),
DropDownList).SelectedValue
e.NewValues("Subproject") =
CType(gv.Rows(e.RowIndex).FindControl("ddlSub"),
DropDownList).SelectedValue
sSubProject = CType(gv.Rows(e.RowIndex).FindControl("ddlSub"),
DropDownList).SelectedValue
TripFCode = e.NewValues("FundsSourceCode").ToString()..Trim
BeginMiles = e.NewValues("BeginMileage").ToString()
EndMileage = e.NewValues("EndMileage").ToString()
TripSubCode = sSubProject
TripMiles = e.NewValues("TripTotal").ToString
TripPCode = e.NewValues("ProjectSubCode").ToString().Trim
TripDate = CType(e.NewValues("TripDate").ToString(), DateTime)
I then use the variables to update my datasource.
Do you have Datakeys setup?

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
 
Back
Top