Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / August 2007

Tip: Looking for answers? Try searching our database.

problem with populating a dropdownlist in editTemplate of detailsview

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jan - 11 Aug 2007 22:02 GMT
Hi,

i defined a dropdownlist in an EditTemplate of a detailsview like this:

<EditItemTemplate>
<asp:DropDownList ID="drop1" runat="server"></asp:DropDownList>
</EditItemTemplate>

I want to populate it in code-behind; i tried this:

Protected Sub DetailsView1_ItemCreated(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DetailsView1.ItemCreated
       If DataControlRowState.Edit Then    'only in edit mode
           If DataControlRowType.DataRow Then    'only datarow
               Dim dd1 As DropDownList
               Dim z1 As ListItem
               Dim i As Integer
               dd1 = CType(DetailsView1.Rows(5).FindControl("drop1"),
DropDownList)
               For i = 0 To 20
               z1 = New ListItem(i, i)
               dd1.Items.Add(z1)
               Next
           End If
       End If
   End Sub

But i get the error:"Object reference not set to an instance of an object"
at line:  dd1.Items.Add(z1)

Thanks for help
Jan
Milosz Skalecki [MCAD] - 12 Aug 2007 00:22 GMT
Jan,

Seems your dropdownlist is not plaved in the 5th row (remember in this case
rows are numbered starting from zero). Anyway, you don't have to use
row(index), just try DetailsView1.FindControl("drop1"). If this doesn't work,
try to debug this line of the code and find the control location (ie. by
traversing the control tree within the with Quick View window).

HTH
Signature

Milosz

> Hi,
>
[quoted text clipped - 28 lines]
> Thanks for help
> Jan
Jan - 12 Aug 2007 11:52 GMT
Ji Milosz, thanks for replying.

I tried DetailsView1.FindControl("drop1") but still same error ...
I use VWD (Visual web dev.) and i don't understand what you mean with:"try
to debug this line of the code and find the control location (ie. by
traversing the control tree within the with Quick View window)."

I get the error even in normal mode. Maybe are these lines not correct:
If DataControlRowState.Edit Then

If DataControlRowType.DataRow Then

.....

> Jan,
>
[quoted text clipped - 41 lines]
>> Thanks for help
>> Jan

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.