FINDCONTROL PROBLEM

S

Savas Ates

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..
 
A

addup

Savas said:
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 --
 
S

Scott M.

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
 
S

Savas Ates

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
 
S

Scott M.

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top