FindControl only finds controls within the scope of the control that the
method is run from. i.e. Page.FindControl will only find control that exist
within the scope of the page. You should use the FindControl method of the
parent control to the control that you are looking for. You say your
DropDownList is in an EditItemTemplate tage so you should use the findControl
method of whatever data bound control your EditItemTemplate is in.
For Example if your DropDownList was within the EditItemTemplate of a
DetailsView called MyDetailsView you would use:
MyDetailsView.FindControl("CIdeefixeSatis")
The only exception to this is a gridview or similar control where there
could be multiple instances of your control, in this case you would have to
make sure you called the FindControl method on the correct row within your
GridView.
For FindControl to work you need to amke sure that each child control has a
unique ID, e.g. whilst ASP.net will let you put a control with the same ID in
your EditItemTemplate and Your InsertItemTemplate if you called FindControl
method on the parent control it would give you an error that there were
multiple controls with the same ID and it cannot determine which one you are
looking for.
"Savas Ates" wrote:
>
It is in my <EditItemTemplateTag..
<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(Page.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..