DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Sat, 11 Aug 2007 23:02:22 +0200,    posted on: microsoft.public.dotnet.framework.aspnet        back       

Thread Index
  1    Jan j@sss
          2    Milosz Skalecki [MCAD]
          3    Jan j@sss


problem with populating a dropdownlist in editTemplate of detailsview   
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
Date:Sat, 11 Aug 2007 23:02:22 +0200   Author:  

RE: problem with populating a dropdownlist in editTemplate of detailsv   
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
-- 
Milosz


"Jan" wrote:


> 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 
> 
> 
> 
Date:Sat, 11 Aug 2007 16:22:02 -0700   Author:  

Re: problem with populating a dropdownlist in editTemplate of detailsv   
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



......


"Milosz Skalecki [MCAD]"  schreef in bericht 
news:7CD90115-0DE6-4E7C-8916-EC67565E2A78@microsoft.com...

> 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
> -- 
> Milosz
>
>
> "Jan" wrote:
>
>> 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
>>
>>
>> 
Date:Sun, 12 Aug 2007 12:52:56 +0200   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us