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