dropdownlist, textbox in datagrid dropdownlist_selectedindexchange event

Discussion in 'ASP .Net Web Controls' started by CindyH, Sep 3, 2007.

  1. CindyH

    CindyH Guest

    Hi
    I'm using vs.net 2003.
    I have a dropdownlist inside a datagrid.
    I would like to be able to select a value from the dropdownlist and then
    have a textbox which is also inside the datagrid filled with that value.

    I'm calling OnSelectedIndexChanged="ddlGridMonth_SelectedIndexChanged" event
    when an item from the dropdownlist is selected

    I'm not sure of the code I should be using for this event.
    Right now I'm trying something like this:


    Dim ddl As DropDownList = CType(sender, DropDownList)

    Dim dg As DataGrid = Me.FindControl("dgMonthlyReports")

    ' not getting anything in this textbox (nothing)

    Dim txt As TextBox = CType(dg.FindControl("ReportMonth"), TextBox)

    ' getting value from dropdownlist

    Dim ddlValue As Integer = ddl.SelectedItem.Value

    ' not getting value here because it doesn't seem to know about the textbox

    Dim TextValue As String = txt.Text

    If ddlValue <> 0 Then

    txt.Text = ddlValue

    End If


    I'm getting the value of the dropdownlist, but not the textbox and then I
    need to see if the dropdownlist value is something other then 0 and if so
    write the value to the textbox.

    Thanks,

    CindyH
     
    CindyH, Sep 3, 2007
    #1
    1. Advertising

  2. CindyH

    Teemu Keiski Guest

    Hi,

    you probably mean something like this

    Dim ddl As DropDownList = CType(sender, DropDownList)

    'NOTE THIS LINE
    Dim gridItem As DataGridItem = CType(ddl.NamingContainer, DataGridItem)

    Dim txt As TextBox = CType(gridItem.FindControl("ReportMonth"), TextBox)
    Dim ddlValue As Integer = ddl.SelectedItem.Value
    Dim TextValue As String = txt.Text



    Point is NamingContainer of DroPDownList returns the DataGridItem which
    represents the row the DDL is on. So running FindControl to this, will get
    you controls on the same row

    I've exlained this in a blog post:

    Understanding the naming container hierarchy of ASP.NET databound controls
    http://aspadvice.com/blogs/joteke/a...-hierarchy-of-ASP.NET-databound-controls.aspx

    -
    Teemu Keiski
    AspInsider, ASP.NET MVP
    http://blogs.aspadvice.com/joteke
    http://teemukeiski.net



    >
    > Dim dg As DataGrid = Me.FindControl("dgMonthlyReports")
    >
    > ' not getting anything in this textbox (nothing)
    >
    > Dim txt As TextBox = CType(dg.FindControl("ReportMonth"), TextBox)
    >
    > ' getting value from dropdownlist
    >
    > Dim ddlValue As Integer = ddl.SelectedItem.Value
    >
    > ' not getting value here because it doesn't seem to know about the textbox
    >
    > Dim TextValue As String = txt.Text



    "CindyH" <> wrote in message
    news:%...
    > Hi
    > I'm using vs.net 2003.
    > I have a dropdownlist inside a datagrid.
    > I would like to be able to select a value from the dropdownlist and then
    > have a textbox which is also inside the datagrid filled with that value.
    >
    > I'm calling OnSelectedIndexChanged="ddlGridMonth_SelectedIndexChanged"
    > event
    > when an item from the dropdownlist is selected
    >
    > I'm not sure of the code I should be using for this event.
    > Right now I'm trying something like this:
    >
    >
    > Dim ddl As DropDownList = CType(sender, DropDownList)
    >
    > Dim dg As DataGrid = Me.FindControl("dgMonthlyReports")
    >
    > ' not getting anything in this textbox (nothing)
    >
    > Dim txt As TextBox = CType(dg.FindControl("ReportMonth"), TextBox)
    >
    > ' getting value from dropdownlist
    >
    > Dim ddlValue As Integer = ddl.SelectedItem.Value
    >
    > ' not getting value here because it doesn't seem to know about the textbox
    >
    > Dim TextValue As String = txt.Text
    >
    > If ddlValue <> 0 Then
    >
    > txt.Text = ddlValue
    >
    > End If
    >
    >
    > I'm getting the value of the dropdownlist, but not the textbox and then I
    > need to see if the dropdownlist value is something other then 0 and if so
    > write the value to the textbox.
    >
    > Thanks,
    >
    > CindyH
    >
    >
     
    Teemu Keiski, Sep 13, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TmV3VG9Eb3ROZXQ=?=

    TextBox and DropDownList in Datagrid Edit mode

    =?Utf-8?B?TmV3VG9Eb3ROZXQ=?=, Jan 30, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    828
    =?Utf-8?B?TmV3VG9Eb3ROZXQ=?=
    Feb 9, 2004
  2. jorge
    Replies:
    2
    Views:
    1,338
    jorge
    May 26, 2004
  3. S_K
    Replies:
    6
    Views:
    1,250
    Robert Dunlop
    Nov 8, 2007
  4. jorge
    Replies:
    1
    Views:
    446
    Teemu Keiski
    May 28, 2004
  5. jorge
    Replies:
    0
    Views:
    342
    jorge
    May 25, 2004
Loading...

Share This Page