FINDCONTROL PROBLEM

Discussion in 'ASP .Net Datagrid Control' started by Savas Ates, Jul 21, 2006.

  1. Savas Ates

    Savas Ates Guest

    It is in my <EditItemTemplate> Tag..

    <asp:DropDownList Runat=server ID="CIdeefixeSatis" SelectedIndex='<%#
    SelectMyIndex(DataBinder.Eval(Container, "DataItem.ideefixesatis")) %>'

    >



    <asp:ListItem Value="True">Stokta Var</asp:ListItem>


    <asp:ListItem Value="False">Stokta Yok</asp:ListItem>


    </asp:DropDownList>

    In my codebehind

    Public Function SelectMyIndex(ByVal indexno As Boolean)

    ideefixesatisc = CType(Datagrid1.FindControl("CIdeefixeSatis"),
    DropDownList)
    Response.Write(ideefixesatisc)


    End Function
    There is no problem with that code..
    However When i try to reach
    ideefixesatisc. (properties of ideefixesatisc object for example
    ideefixesatisc.DataTextField = "OK" )

    It returns
    Object reference not set to an instance of an object.
    ideefixesatisc.DataTextField = "OK"

    What can be the problem. . Any idea will be appreciated..
    Savas Ates, Jul 21, 2006
    #1
    1. Advertising

  2. Savas Ates

    addup Guest

    Savas Ates wrote:
    > It is in my <EditItemTemplate> Tag..
    >
    > <asp:DropDownList Runat=server ID="CIdeefixeSatis" SelectedIndex='<%#
    > SelectMyIndex(DataBinder.Eval(Container, "DataItem.ideefixesatis")) %>'
    >
    > >

    >
    >
    > <asp:ListItem Value="True">Stokta Var</asp:ListItem>
    >
    >
    > <asp:ListItem Value="False">Stokta Yok</asp:ListItem>
    >
    >
    > </asp:DropDownList>
    >
    > In my codebehind
    >
    > Public Function SelectMyIndex(ByVal indexno As Boolean)
    >
    > ideefixesatisc = CType(Datagrid1.FindControl("CIdeefixeSatis"),
    > DropDownList)
    > Response.Write(ideefixesatisc)
    >
    >
    > End Function
    > There is no problem with that code..
    > However When i try to reach
    > ideefixesatisc. (properties of ideefixesatisc object for example
    > ideefixesatisc.DataTextField = "OK" )
    >
    > It returns
    > Object reference not set to an instance of an object.
    > ideefixesatisc.DataTextField = "OK"
    >
    > What can be the problem. . Any idea will be appreciated..



    Try this:
    Datagrid1.Items(Datagrid1.EditItemIndex).FindControl("...
    in place of Datagrid1.FindControl...

    Hope this helps
    -- a --
    addup, Jul 21, 2006
    #2
    1. Advertising

  3. Savas Ates

    Scott M. Guest

    How does the following evaluate out to a Boolean? ideefixesatisc will
    become a reference to the DropDownList, not a boolean.


    Public Function SelectMyIndex(ByVal indexno As Boolean)
    ideefixesatisc = CType(Datagrid1.FindControl("CIdeefixeSatis"),
    DropDownList)
    Response.Write(ideefixesatisc)
    End Function
    Scott M., Jul 21, 2006
    #3
  4. Savas Ates

    Savas Ates Guest

    I changed My function with that but it doesnt work again

    Public Function SelectMyIndex(ByVal indexno As Boolean)

    Try



    ideefixesatisc =
    CType(DataGrid1.Items(DataGrid1.EditItemIndex).FindControl("CIdeefixeSatis"),
    DropDownList)

    ideefixesatisc.DataTextField = "Stokta Yok"

    Catch ex As Exception

    Response.Write(ex)

    Response.End()

    End Try



    Error

    System.ArgumentOutOfRangeException: Index was out of range. Must be
    non-negative and less than the size of the collection. Parameter name: index
    at System.Collections.ArrayList.get_Item(Int32 index) at
    System.Web.UI.WebControls.DataGridItemCollection.get_Item(Int32 index) at
    DATAGRID.WebForm1.SelectMyIndex(Boolean indexno) in
    C:\Inetpub\wwwroot\DOTNETDENEME\DATAGRID\WebForm1.aspx.vb:line 42
    Savas Ates, Jul 24, 2006
    #4
  5. Savas Ates

    Scott M. Guest

    I'll ask again...


    How does the following evaluate out to a Boolean? ideefixesatisc will
    become a reference to the DropDownList, not a boolean and your function
    doesn't set its return value to anything, so it will always return false.

    Public Function SelectMyIndex(ByVal indexno As Boolean)
    ideefixesatisc = CType(Datagrid1.FindControl("CIdeefixeSatis"),
    DropDownList)
    Response.Write(ideefixesatisc)
    End Function


    "Savas Ates" <in da club> wrote in message
    news:%23ezu%...
    >I changed My function with that but it doesnt work again
    >
    > Public Function SelectMyIndex(ByVal indexno As Boolean)
    >
    > Try
    >
    >
    >
    > ideefixesatisc =
    > CType(DataGrid1.Items(DataGrid1.EditItemIndex).FindControl("CIdeefixeSatis"),
    > DropDownList)
    >
    > ideefixesatisc.DataTextField = "Stokta Yok"
    >
    > Catch ex As Exception
    >
    > Response.Write(ex)
    >
    > Response.End()
    >
    > End Try
    >
    >
    >
    > Error
    >
    > System.ArgumentOutOfRangeException: Index was out of range. Must be
    > non-negative and less than the size of the collection. Parameter name:
    > index at System.Collections.ArrayList.get_Item(Int32 index) at
    > System.Web.UI.WebControls.DataGridItemCollection.get_Item(Int32 index) at
    > DATAGRID.WebForm1.SelectMyIndex(Boolean indexno) in
    > C:\Inetpub\wwwroot\DOTNETDENEME\DATAGRID\WebForm1.aspx.vb:line 42
    >
    >
    Scott M., Jul 24, 2006
    #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. Jaime

    FindControl problem

    Jaime, May 20, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    670
    Jaime
    May 20, 2005
  2. =?Utf-8?B?dHBhcmtzNjk=?=

    ItemCreated FindControl problem c#

    =?Utf-8?B?dHBhcmtzNjk=?=, Jun 16, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    6,509
    =?Utf-8?B?QkVMSVVT?=
    Jun 16, 2005
  3. Arjen

    Findcontrol problem

    Arjen, Oct 17, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    2,033
    Scott Allen
    Oct 18, 2005
  4. ThunderMusic
    Replies:
    2
    Views:
    412
    ThunderMusic
    Oct 9, 2006
  5. Terry

    problem with FindControl

    Terry, Feb 15, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    580
    Terry
    Feb 15, 2007
Loading...

Share This Page