Use FindControl for HMTL control in Datagrid

Discussion in 'ASP .Net' started by Sid, Nov 10, 2003.

  1. Sid

    Sid Guest

    Hi,

    I am trying to use the FindControl method to find a HTML
    Select control I have in my Datagrid. The syntax I am
    using is

    Dim obj As HTMLSelect
    Dim str As String

    obj = E.Item.FindControl("controlname")
    str = obj.Value

    Only thing is this gives an error saying 'object is not
    set to a reference of an object', does anyone know if this
    is even possible?

    Thanks

    Sid
    Sid, Nov 10, 2003
    #1
    1. Advertising

  2. Sid

    Teemu Keiski Guest

    Are you using this in ItemCreated or ItemDataBound? If yes, do you check
    ItemType property that the item is Item or AlternatingItem?

    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsiders member
    ASP.NET Forum Moderator, AspAlliance Columnist

    "Sid" <> wrote in message
    news:09bf01c3a7a4$27961c10$...
    > Hi,
    >
    > I am trying to use the FindControl method to find a HTML
    > Select control I have in my Datagrid. The syntax I am
    > using is
    >
    > Dim obj As HTMLSelect
    > Dim str As String
    >
    > obj = E.Item.FindControl("controlname")
    > str = obj.Value
    >
    > Only thing is this gives an error saying 'object is not
    > set to a reference of an object', does anyone know if this
    > is even possible?
    >
    > Thanks
    >
    > Sid
    >
    Teemu Keiski, Nov 10, 2003
    #2
    1. Advertising

  3. Sid

    Sid Guest

    Hi, Thanks for replying, I am using this in the
    EditItemTemplate and it is being used in the UpdateItem
    command.


    >-----Original Message-----
    >Are you using this in ItemCreated or ItemDataBound? If

    yes, do you check
    >ItemType property that the item is Item or

    AlternatingItem?
    >
    >--
    >Teemu Keiski
    >MCP, Microsoft MVP (ASP.NET), AspInsiders member
    >ASP.NET Forum Moderator, AspAlliance Columnist
    >
    >"Sid" <> wrote in

    message
    >news:09bf01c3a7a4$27961c10$...
    >> Hi,
    >>
    >> I am trying to use the FindControl method to find a HTML
    >> Select control I have in my Datagrid. The syntax I am
    >> using is
    >>
    >> Dim obj As HTMLSelect
    >> Dim str As String
    >>
    >> obj = E.Item.FindControl("controlname")
    >> str = obj.Value
    >>
    >> Only thing is this gives an error saying 'object is not
    >> set to a reference of an object', does anyone know if

    this
    >> is even possible?
    >>
    >> Thanks
    >>
    >> Sid
    >>

    >
    >
    >.
    >
    Sid, Nov 10, 2003
    #3
  4. Sid

    Teemu Keiski Guest

    Ok,

    can you show an example of the declarative (aspx) syntax you have and a bit
    more of the code?

    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsiders member
    ASP.NET Forum Moderator, AspAlliance Columnist

    "Sid" <> wrote in message
    news:004801c3a7b0$a4c51d10$...
    > Hi, Thanks for replying, I am using this in the
    > EditItemTemplate and it is being used in the UpdateItem
    > command.
    >
    >
    > >-----Original Message-----
    > >Are you using this in ItemCreated or ItemDataBound? If

    > yes, do you check
    > >ItemType property that the item is Item or

    > AlternatingItem?
    > >
    > >--
    > >Teemu Keiski
    > >MCP, Microsoft MVP (ASP.NET), AspInsiders member
    > >ASP.NET Forum Moderator, AspAlliance Columnist
    > >
    > >"Sid" <> wrote in

    > message
    > >news:09bf01c3a7a4$27961c10$...
    > >> Hi,
    > >>
    > >> I am trying to use the FindControl method to find a HTML
    > >> Select control I have in my Datagrid. The syntax I am
    > >> using is
    > >>
    > >> Dim obj As HTMLSelect
    > >> Dim str As String
    > >>
    > >> obj = E.Item.FindControl("controlname")
    > >> str = obj.Value
    > >>
    > >> Only thing is this gives an error saying 'object is not
    > >> set to a reference of an object', does anyone know if

    > this
    > >> is even possible?
    > >>
    > >> Thanks
    > >>
    > >> Sid
    > >>

    > >
    > >
    > >.
    > >
    Teemu Keiski, Nov 10, 2003
    #4
  5. Sid

    Sid Guest

    No problem, this is how my columns are declared in the
    datagrid:

    <asp:TemplateColumn HeaderText="Heading">
    <ITEMTEMPLATE>
    <table>
    <tbody>
    <tr>
    <td>
    <select name="ddlCountry">
    <option value="Wales"
    selected="selected">Wales</option>
    </select>
    </td>
    </tr>
    </tbody>
    </table>
    </ITEMTEMPLATE>
    <EDITITEMTEMPLATE>
    <table>
    <tbody>
    <tr>
    <td>
    <select name="ddlCountry">
    <option value="Wales"
    selected="selected">Wales</option>
    </select>
    </td>
    </tr>
    </tbody>
    </table>
    </EDITITEMTEMPLATE>
    </asp:TemplateColumn>

    And then I call this in the EditItemCommand:

    sub doEdit(sender as object, e as _
    Datagridcommandeventargs)

    Dim obj as HTMLSelect
    dim myStr as string
    obj = CType(e.Item.FindControl _
    ("ddlCountry"), HTMLSelect)

    myStr = obj.Value ##Errors here

    end Sub


    Hope this helps?

    >-----Original Message-----
    >Ok,
    >
    >can you show an example of the declarative (aspx) syntax

    you have and a bit
    >more of the code?
    >
    >--
    >Teemu Keiski
    >MCP, Microsoft MVP (ASP.NET), AspInsiders member
    >ASP.NET Forum Moderator, AspAlliance Columnist
    >
    >"Sid" <> wrote in

    message
    >news:004801c3a7b0$a4c51d10$...
    >> Hi, Thanks for replying, I am using this in the
    >> EditItemTemplate and it is being used in the UpdateItem
    >> command.
    >>
    >>
    >> >-----Original Message-----
    >> >Are you using this in ItemCreated or ItemDataBound? If

    >> yes, do you check
    >> >ItemType property that the item is Item or

    >> AlternatingItem?
    >> >
    >> >--
    >> >Teemu Keiski
    >> >MCP, Microsoft MVP (ASP.NET), AspInsiders member
    >> >ASP.NET Forum Moderator, AspAlliance Columnist
    >> >
    >> >"Sid" <> wrote in

    >> message
    >> >news:09bf01c3a7a4$27961c10$...
    >> >> Hi,
    >> >>
    >> >> I am trying to use the FindControl method to find a

    HTML
    >> >> Select control I have in my Datagrid. The syntax I am
    >> >> using is
    >> >>
    >> >> Dim obj As HTMLSelect
    >> >> Dim str As String
    >> >>
    >> >> obj = E.Item.FindControl("controlname")
    >> >> str = obj.Value
    >> >>
    >> >> Only thing is this gives an error saying 'object is

    not
    >> >> set to a reference of an object', does anyone know if

    >> this
    >> >> is even possible?
    >> >>
    >> >> Thanks
    >> >>
    >> >> Sid
    >> >>
    >> >
    >> >
    >> >.
    >> >

    >
    >
    >.
    >
    Sid, Nov 11, 2003
    #5
    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. Nico Fluitsma

    Newby question: how convert hmtl -> jpg?

    Nico Fluitsma, Nov 6, 2003, in forum: HTML
    Replies:
    10
    Views:
    1,210
    informant
    Nov 9, 2003
  2. Simon Spencer

    study HMTL

    Simon Spencer, Oct 12, 2004, in forum: HTML
    Replies:
    3
    Views:
    561
  3. Replies:
    31
    Views:
    886
    =?ISO-8859-1?Q?Olli_M=E4ntyranta?=
    Dec 7, 2006
  4. Ed Mullen

    Is this in the HMTL specs?

    Ed Mullen, Feb 18, 2008, in forum: HTML
    Replies:
    9
    Views:
    374
    Neredbojias
    Feb 19, 2008
  5. David

    Modify the HMTL generated in a user control

    David, Jul 6, 2005, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    111
    David
    Jul 13, 2005
Loading...

Share This Page