473,473 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

DATAGRID DROPDOWN PROBLEM


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



Jul 21 '06 #1
3 1132
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..



Jul 21 '06 #2
I have that hierarchie

<asp:DataGrid id="DataGrid1"
<Columns>
<EditItemTemplate>
<asp:DropDownList Runat=server ID="CIdeefixeSatis"

and CIdeefixeSatis is the only one dropdown named as "CIdeefixeSatis"..

I tried
ideefixesatisc = CType(DataGrid1.FindControl("CIdeefixeSatis"),
DropDownList)

ideefixesatisc.DataTextField = "Stokta Yok"

it is still the same result.. What do you Offer.. By the way thaks for your
quick response..

Jul 21 '06 #3
The reason DataGrid1.FindControl doesn't work is because there might be
multiple controls because a DataGrid can have lots of rows.

Not sure how you would do it in a DataGrid. I started .net with V2 so i
always use GridViews and i have never used a DataGrid. With a GridView you
need to call the FindControl method of the relevent row in the Rows
collection or call it in something like the OnRowDataBound or OnRowCreated
event handler. A Gridview doesn't havethe rows collection or any suitable
event handler so i aqm not sure might have to wait for someone with a bit
more experience than me for help on this one.

"Savas Ates" wrote:
I have that hierarchie

<asp:DataGrid id="DataGrid1"
<Columns>
<EditItemTemplate>
<asp:DropDownList Runat=server ID="CIdeefixeSatis"

and CIdeefixeSatis is the only one dropdown named as "CIdeefixeSatis"..

I tried
ideefixesatisc = CType(DataGrid1.FindControl("CIdeefixeSatis"),
DropDownList)

ideefixesatisc.DataTextField = "Stokta Yok"

it is still the same result.. What do you Offer.. By the way thaks for your
quick response..

Jul 21 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: HalaszJ | last post by:
Is there no work around for this? >-----Original Message----- >I have asked this question on about every board I can >think of and I have yet to get an answer, so If anyone >would know I...
4
by: Richard Roche | last post by:
Is it possible to use a drop combo instead of a text box when using the EditCommand in the Datagrid? Many table columns are bound to 'lookup' tables, user's don't care about the foreign keys,...
1
by: Vijay Kerji | last post by:
Hi, I have a datagrid with dropdown list and Remove hyperlink in it as columns. When I remove a row from the datagrid, Dropdown list selection is retaining its previous value. i.e, removed...
4
by: Mark Waser | last post by:
I've discovered a very odd bug when attempting to put a dropdown list in a datagrid. In the page PreRender step, the selected index of the datagrid is successfully set during databinding. Yet,...
3
by: Engineerik | last post by:
The vb6 datagrid had a "button" property which I used to display a dropdown icon in a cell. I created a popup menu that would display the list of valid choices for that cell when the user clicked...
2
by: Gummy | last post by:
Hello All, I have a webpage that has two dropdown listboxes. Based on what is selected in these dropdown listboxes, it filters a DataGrid . That works fine. In the DataGrid , when I go to edit...
2
by: Peter | last post by:
ASP.NET 2003 In the DataGrid how do I select current cell value in the dropdown box when I click on the edit link, currently when I click on the edit link in the DataGrid the dropdown box...
0
by: cindy | last post by:
I have a dynamic datagrid. I have custom classes for the controls public class CreateEditItemTemplateDDL : ITemplate { DataTable dtBind; string strddlName; string strSelectedID; string...
0
by: anjupt | last post by:
Hi, I can add values to a dropdown from 1 to 100 using a while loop in page load.ie Dim i = 1 While i <= 100 Me.DropDownList2.Items.Add(i) ' i = i +...
4
by: youvrajasnsm | last post by:
Hi All, >I am using datagrid control in asp.net with C#. >I have two dropdown list in datagrid e.g. one dropdown have Classname and another have Studentname. >now I want to show all the...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.