We help IT Professionals succeed at work.
Get Started

Setting SqlDataSource Defautl Value for Gridview RowUpdating

lakhi asked
Last Modified: 2012-08-13
The gridview I'm using in this application will be used by the admin for the web application. The admin will have the capability to edit almost all of the fields in each record. The admin can also close the record from this form. To make it as easy as possible for the user, I want the gridview updating to check for a close date. If a close date is entered, the user must also select "Yes" or "No" from the redline dropdown (default is "UNKNOWN"). I have customvalidators that are enabled when a close date is entered and they work properly.
Once the close date and dropdown are validated, I want to change the priority field to "DONE" and the tool_design_complete_date to today's date.
Everything works except for changing the priority value and I can't figure out why.
Help, please?
Protected Sub adminPendGridview_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles adminPendGridview.RowUpdating
    'Complete Date
    Dim dtTB As TextBox = CType(adminPendGridview.Rows(e.RowIndex).FindControl("completeDateTextBox"), TextBox)
    'Tool Design Complete Date
    Dim dt2TB As TextBox = CType(adminPendGridview.Rows(e.RowIndex).FindControl("toolDsgnCptDtTextBox"), TextBox)
    Dim priTB As TextBox = CType(adminPendGridview.Rows(e.RowIndex).FindControl("priorityTextBox"), TextBox)
    'Redline Dropdown
    Dim rdDDL As DropDownList = CType(adminPendGridview.Rows(e.RowIndex).FindControl("redlineDropDownList"), DropDownList)
    'Complete Date CustomValidator
    Dim custVal As CustomValidator = CType(adminPendGridview.Rows(e.RowIndex).FindControl("compDtCustomValidator"), CustomValidator)
    'Redline CustomValidator
    Dim rdCustVal As CustomValidator = CType(adminPendGridview.Rows(e.RowIndex).FindControl("redlineCustomValidator"), CustomValidator)

    'Check to see if the Close Date has been entered. 
    'If so, enable the custom validator to check the validity of the text entered and
    'enable the custom validator for the redline dropdownlist
    If IsDate(dtTB.Text) Then
      custVal.Enabled = True
      rdCustVal.Enabled = True
      custVal.Enabled = False
      rdCustVal.Enabled = False
    End If

    If (IsDate(dtTB.Text)) Then 'a complete date has been entered and the Redline dropdown is Yes or No
      If priTB.Text <> "DONE" Then AdminPendSqlDataSource.UpdateParameters("priority").DefaultValue = "DONE"
      If Not IsDate(dt2TB.Text) Then AdminPendSqlDataSource.UpdateParameters("tool_design_complete_date").DefaultValue = Now.ToShortDateString
    End If
  End Sub

Open in new window

Watch Question
This problem has been solved!
Unlock 1 Answer and 1 Comment.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE