I was trying to do this by tweaking the code above that was already
written for the text changed...could you help me out on this? I also
need to allow the textbox value to be blank and then the dropdown list
would just be blank.

On Jan 23, 2:03 am, Cerebrus <[email protected]> wrote:
> Maybe the Dropdownlist should be re-bound on the Update method called
> when the GridView is updated.
>
> On Jan 23, 12:48 am, Stacie <[email protected]> wrote:
>
>
>
> > The dropdown list is a list of cost codes associated with a job number
> > (the textbox).  Anytime a user clicks the edit button on a gridview
> > row or if they change the job number in the textbox the dropdown list
> > must be populated with only the available cost codes for that specific
> > job number. Is there a better way to handle this?  I'm a newbie so I
> > would appreciate any advice on a better solution.
>
> > On Jan 22, 11:41 am, Cerebrus <[email protected]> wrote:
>
> > > I have serious issues with developers using code behind functions for
> > > TextChanged events in Textboxes. Are you telling me that you want all
> > > that code (including the hit to the database) to run everytime a user
> > > presses a key in your textbox ??? I would strongly suggest re-
> > > evaluating your requirements.
>
> > > On Jan 22, 10:07 pm, Stacie <[email protected]> wrote:
>
> > > > I need to populate a dropdown list(DD_CostCodeEdit) in my gridview
> > > > based on a textbox(job) value in the gridview.  I already have code to
> > > > populate the dropdown list on the textbox changed event but I also
> > > > need to populate it when in edit mode. I'm having trouble tweaking the
> > > > textbox changed event code to work in the row editing event code.
> > > > Could someone help me out?
> > > > I've posted my textbox changed code below:
>
> > > > Protected Sub Job_TextChanged(ByVal sender As Object, ByVal e As
> > > > System.EventArgs)
>
> > > >         'Get the row of the gridview based on the text box that raised
> > > > this event (realize that there is 1 textbox that raises this event in
> > > > each row)
> > > >         Dim jobTextBox As TextBox = DirectCast(sender, TextBox)
> > > >         'Create a local dropdown instance
> > > >         Dim costcodeDDL As KeySortDropDownList.KeySortDropDownList =
> > > > Nothing
> > > >         Dim jobNumber As String = ""
>
> > > >         'Loop thru the rows in the grid view to...
> > > >         For Each row As GridViewRow In Me.TimecardGridView.Rows
> > > >             '... find the job text box
> > > >             Dim jobNoTextBox As TextBox = CType(row.FindControl
> > > > ("job"), TextBox)
> > > >             If jobNoTextBox IsNot Nothing Then
> > > >                 'compare the Unique IDs to ensure we found the correct
> > > > row in the grid view then...
> > > >                 If jobNoTextBox.UniqueID = jobTextBox.UniqueID Then
> > > >                     '...get a reference to the costcodeDDL so we can
> > > > bind the correct data to it (based on the value in job textbox)
>
> > > >                     costcodeDDL = CType(row.FindControl
> > > > ("DD_CostCodeEdit"), DropDownList)
> > > >                     jobNumber = jobNoTextBox.Text
> > > >                     Exit For
> > > >                 End If
> > > >             End If
> > > >         Next
>
> > > >         'Lets make sure we have a costcode drop down, if not, throw an
> > > > exception since there is a fatal error
> > > >         Try
> > > >             If costcodeDDL Is Nothing Then
> > > >                 Throw New Exception("CostCode drop down list is null")
> > > >             End If
> > > >         Catch ex As Exception
> > > >             MsgBox(ex.Message)
> > > >         End Try
>
> > > >         Dim oConn As New System.Data.SqlClient.SqlConnection
> > > > (ConfigurationManager.ConnectionStrings
> > > > ("CMSConnectionString").ConnectionString)
> > > >         Dim sql As New System.Data.SqlClient.SqlCommand()
>
> > > >         sql.Connection = oConn
> > > >         oConn.Open()
> > > >         If jobNumber.Length > 0 Then
> > > >             sql.Parameters.AddWithValue("jobNumber", jobNumber)
> > > >             sql.CommandText = "SELECT CJCDI FROM dbo.Job_Cost_Codes
> > > > Where gjb...@jobnumber Order by CJCDI ASC"
>
> > > >             Try
> > > >                 Dim reader As System.Data.SqlClient.SqlDataReader =
> > > > sql.ExecuteReader()
> > > >                 'Now the user could have entered in a value that does
> > > > not exist, again no need to choke, just re-execute the reader and get
> > > > all the values
> > > >                 If reader.HasRows Then
> > > >                     costcodeDDL.DataSource = reader
> > > >                     costcodeDDL.DataBind()
> > > >                 Else
>
> > > >                     costcodeDDL.Items.Insert(0, "")
>
> > > >                 End If
>
> > > >             Catch ex As Exception
> > > >                 MsgBox(ex.Message)
> > > >             Finally
> > > >                 oConn.Close()
> > > >             End Try
> > > >         End If
>
> > > >     End Sub- Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -

Reply via email to