FindControl in GridView

Discussion in 'ASP .Net Datagrid Control' started by Bruno Alexandre, May 17, 2006.

  1. Hi guys,

    I have this code:

    Dim gv As GridViewRow
    Dim str As String = ""
    Dim dd As DropDownList

    For Each gv In gvItems.Rows
    If gv.RowType = DataControlRowType.DataRow Then
    str &= gv.RowType.ToString & "<br/>"
    dd = CType(gvItems.FindControl("dd1"), DropDownList)
    If dd IsNot Nothing Then
    str &= "found"
    End If
    End If
    Next

    and I can't get into str &= "found"
    it doesn't find the control... What I'm doing wrong? the control is showed
    in the page! and has the id = "dd1"


    Any help?... please.

    --

    Bruno Alexandre
    (a Portuguese in Københanv, Danmark)
     
    Bruno Alexandre, May 17, 2006
    #1
    1. Advertising

  2. Bruno Alexandre

    clickon Guest

    surely this line:

    dd = CType(gvItems.FindControl("dd1"), DropDownList)

    should read

    dd = CType(gv.FindControl("dd1"), DropDownList)

    If you want it to look for the control dd1 on each row in the loop.

    "Bruno Alexandre" wrote:

    > Hi guys,
    >
    > I have this code:
    >
    > Dim gv As GridViewRow
    > Dim str As String = ""
    > Dim dd As DropDownList
    >
    > For Each gv In gvItems.Rows
    > If gv.RowType = DataControlRowType.DataRow Then
    > str &= gv.RowType.ToString & "<br/>"
    > dd = CType(gvItems.FindControl("dd1"), DropDownList)
    > If dd IsNot Nothing Then
    > str &= "found"
    > End If
    > End If
    > Next
    >
    > and I can't get into str &= "found"
    > it doesn't find the control... What I'm doing wrong? the control is showed
    > in the page! and has the id = "dd1"
    >
    >
    > Any help?... please.
    >
    > --
    >
    > Bruno Alexandre
    > (a Portuguese in Københanv, Danmark)
    >
    >
    >
    >
    >
     
    clickon, May 17, 2006
    #2
    1. Advertising

  3. got that 2 seconds after post the message, but still wont work, then I tried
    again (for the 100th time) search the internet finding a solution and here
    it is:

    Dim gv As GridViewRow
    Dim str As String = ""

    For Each gv In gvItems.Rows
    If gv.RowType = DataControlRowType.DataRow Then
    Dim dropDownListText As String = CType(gv.FindControl("qty"),
    DropDownList).SelectedItem.Value
    Dim CheckBoxChecked As Boolean = CType(gv.FindControl("rem"),
    CheckBox).Checked
    If CheckBoxChecked Then
    str &= dropDownListText & "<br/>"
    End If
    End If
    Next

    I dont know why, but I need to change the names :-(

    But now it works perfectly :) ... I'm so happy!!! it took me 2 days to get
    an answer :-/
    but know I can help other with the same question ;-)
    --

    Bruno Alexandre
    (a Portuguese in Københanv, Danmark)


    "clickon" <> escreveu na mensagem
    news:D...
    > surely this line:
    >
    > dd = CType(gvItems.FindControl("dd1"), DropDownList)
    >
    > should read
    >
    > dd = CType(gv.FindControl("dd1"), DropDownList)
    >
    > If you want it to look for the control dd1 on each row in the loop.
    >
    > "Bruno Alexandre" wrote:
    >
    >> Hi guys,
    >>
    >> I have this code:
    >>
    >> Dim gv As GridViewRow
    >> Dim str As String = ""
    >> Dim dd As DropDownList
    >>
    >> For Each gv In gvItems.Rows
    >> If gv.RowType = DataControlRowType.DataRow Then
    >> str &= gv.RowType.ToString & "<br/>"
    >> dd = CType(gvItems.FindControl("dd1"), DropDownList)
    >> If dd IsNot Nothing Then
    >> str &= "found"
    >> End If
    >> End If
    >> Next
    >>
    >> and I can't get into str &= "found"
    >> it doesn't find the control... What I'm doing wrong? the control is
    >> showed
    >> in the page! and has the id = "dd1"
    >>
    >>
    >> Any help?... please.
    >>
    >> --
    >>
    >> Bruno Alexandre
    >> (a Portuguese in Københanv, Danmark)
    >>
    >>
    >>
    >>
    >>
     
    Bruno Alexandre, May 17, 2006
    #3
    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. Edwin Knoppert

    Gridview's findcontrol ignores cells()

    Edwin Knoppert, Nov 25, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    1,569
    Edwin Knoppert
    Nov 25, 2005
  2. Martin
    Replies:
    4
    Views:
    24,585
    shivakalluri
    Apr 10, 2008
  3. Bruno Alexandre

    FindControl in GridView

    Bruno Alexandre, May 17, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    58,595
    ashish
    Sep 1, 2008
  4. K B
    Replies:
    2
    Views:
    5,094
    otkoth
    Sep 17, 2007
  5. saha
    Replies:
    0
    Views:
    4,990
Loading...

Share This Page