Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > .NET 1.0 and Visual Studio.NET > .NET Framework 1.x
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
.NET Framework 1.x For discussing versions 1.0 and 1.1 of the Microsoft .NET Framework.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 1.x section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 25th, 2006, 03:52 AM
Authorized User
 
Join Date: Mar 2006
Location: pune, Maharashtra, India.
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to anup_daware Send a message via MSN to anup_daware Send a message via Yahoo to anup_daware
Default e.Item.FindControl("DropdownId") Returning Null



Hi Group,

I have a datagrid with dropdown in my application.
I want to fill the data in dropdown by an ArrayList
for that I am using "e.Item.FindControl("DropdownId")"
but this function is returning NULL THUS I m getting exception
"Object Refrence not set to an Instance to Object",

Here is the code I wrote (ASP.NET 1.1)...

Hope I get some help from you,



///Cdoe Behind


        private void dataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
        {

            if(e.Item.ItemType == ListItemType.Footer)
            {



                System.Web.UI.WebControls.DropDownList drp = new DropDownList();
                drp = (DropDownList)e.Item.FindControl("listAnup");
                drp.DataSource=newArrayList;//This Statement throwing exception
                drp.DataBind();
            }

        }






///aspx code

<asp:datagrid id=dataGrid1 style="Z-INDEX: 101; LEFT: 256px; POSITION: absolute; TOP: 8px" runat="server" ShowFooter="True" CaptionAlign="Top" Caption="Hello" BackColor="RosyBrown" AllowPaging="True" Height="256px" Width="70%" DataSource="<%# dataSet1 %>" PageSize="2" CellPadding="2" CellSpacing="2">
                <FooterStyle ForeColor="#FFFF80" BorderColor="#E0E0E0" BackColor="Gray"></FooterStyle>
                <SelectedItemStyle ForeColor="#804040" BorderColor="#FFE0C0" BackColor="Aqua"></SelectedItemStyle>
                <EditItemStyle ForeColor="#FFE0C0" BackColor="#C0FFC0"></EditItemStyle>
                <AlternatingItemStyle ForeColor="DarkOliveGreen" BackColor="#FFC080"></AlternatingItemStyle>
                <ItemStyle ForeColor="#404040" BackColor="Khaki"></ItemStyle>
                <HeaderStyle BackColor="RosyBrown"></HeaderStyle>


                <Columns>
                    <asp:TemplateColumn HeaderText="Select">
                        <ItemTemplate>
                            <asp:Label id="labelSelectTyre" runat="server"></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateColumn>
                    <asp:TemplateColumn HeaderText="MTD">
                        <ItemTemplate>
                            <asp:DropDownList id="listAnup" AutoPostBack="True" runat="server" Width="150px"></asp:DropDownList> </ItemTemplate>
                    </asp:TemplateColumn>
                </Columns>

                <PagerStyle VerticalAlign="Middle" ForeColor="#404000" BackColor="White" PageButtonCount="5"
                    Mode="NumericPages"></PagerStyle>
                <PagerStyle NextPageText="Next" PrevPageText="Previous" HorizontalAlign="Center" Position="TopAndBottom"
                    BackColor="#D8D8DA" PageButtonCount="15" Mode="NumericPages"></PagerStyle>

                <PagerStyle NextPageText="Next" PrevPageText="Previous"
                HorizontalAlign="Center" Position="TopAndBottom" BackColor="#D8D8DA"
                PageButtonCount="15" CssClass="dgridPaging"
                Mode="NumericPages"></PagerStyle>

            </asp:datagrid></form>

Best Regards,
Anup
&lt;Today is the first day of your rest of life.. Make most of it&gt;
__________________
--Everything you can imagine is real.--
Reply With Quote
  #2 (permalink)  
Old March 27th, 2006, 03:53 PM
Authorized User
 
Join Date: Oct 2003
Location: São Paulo, SP, Brazil.
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to evandro.paula
Default

The problem is that you have added the control in the "ItemTemplate" node and your code is checking if the dropdownlist is in the footer. Try using the "if" below:
if((e.Item.ItemType==System.Web.UI.WebControls.Lis tItemType.Item)||(e.Item.ItemType==System.Web.UI.W ebControls.ListItemType.AlternatingItem))

Regards
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Returning Null Values in a query dstein4d Access VBA 2 March 21st, 2008 03:59 PM
FindControl in DataListItem SKhna ASP.NET 2.0 Basics 1 February 29th, 2008 05:15 PM
returning null value Vince_421 Access VBA 3 March 6th, 2007 01:54 PM
FindControl Wervis C# 7 November 30th, 2005 09:51 AM
FindControl dkr72 Excel VBA 0 January 19th, 2005 09:55 AM



All times are GMT -4. The time now is 08:11 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.