i am getting the values from datatable but here ddl.DataSource = dt; i am getting an error like Object reference not set to an instance of an object anyone help me on this??
It is not about what caused you to fall flat on your back that defines you; it is what you do to get back up on your feet.
when i use if (e.Item.ItemType == ListItemType.Header) i am unable to fill the DDL as e.Item.ItemType is item and ListItemType.Header is header so the breakpoint is skipping the code and DDL is empty.
It is not about what caused you to fall flat on your back that defines you; it is what you do to get back up on your feet.
.net_junkie
Member
297 Points
825 Posts
Dropdown inside a repeater
Nov 01, 2012 07:31 AM|LINK
I have a dropdown inside a repeater and i am filling it using a datatable
{ try { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { DataTable dt = new DataTable(); dt = Common.LoadExample(); DropDownList ddl = (DropDownList)e.Item.FindControl("DropDownList1"); ddl.DataSource = dt; ddl.DataTextField = "Name"; ddl.DataValueField = "Name"; ddl.DataBind(); } } catch (Exception ex) { throw; }i am getting the values from datatable but here ddl.DataSource = dt; i am getting an error like Object reference not set to an instance of an object anyone help me on this??
adeelehsan
All-Star
18223 Points
2725 Posts
Re: Dropdown inside a repeater
Nov 01, 2012 07:36 AM|LINK
Make sure that the you do have dropdown with name DropDownList1. It seems that FindControl can not find it properly.
MCPD ASP.NET 4.0 and 3.5, MCTS WSS, MOSS, SharePoint 2010, MCT
Microsoft Community Contributor Award 2011
.net_junkie
Member
297 Points
825 Posts
Re: Dropdown inside a repeater
Nov 01, 2012 07:41 AM|LINK
I have the dropdown
oned_gk
All-Star
31135 Points
6361 Posts
Re: Dropdown inside a repeater
Nov 01, 2012 07:44 AM|LINK
<ItemTemplate> <asp:DropDownList id="DropDownList1" runat="server" /> </ItemTemplate> <AlternatingItemTemplate> <asp:DropDownList id="DropDownList1" runat="server" /> </AlternatingItemTemplate>.net_junkie
Member
297 Points
825 Posts
Re: Dropdown inside a repeater
Nov 01, 2012 07:45 AM|LINK
It is inside the header template.
<asp:Repeater ID="Repeater2" runat="server" onitemdatabound="Repeater2_ItemDataBound"> <HeaderTemplate> <table> <tr> <td> <asp:DropDownList ID="DropDownList8" runat="server"> <asp:ListItem>Select</asp:ListItem> <asp:ListItem>Left</asp:ListItem> <asp:ListItem>Right</asp:ListItem> <asp:ListItem>SubString</asp:ListItem> </asp:DropDownList> <asp:DropDownList ID="DropDownList7" runat="server"> <asp:ListItem>1</asp:ListItem> <asp:ListItem>2</asp:ListItem> <asp:ListItem>3</asp:ListItem> </asp:DropDownList> <asp:DropDownList ID="DropDownList1" runat="server"> </asp:DropDownList> <asp:DropDownList ID="DropDownList2" runat="server"> </asp:DropDownList> <asp:Button ID="Button1" runat="server" Text="Button" /> </td> </tr> </table> </HeaderTemplate> <FooterTemplate> <br /> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </FooterTemplate> </asp:Repeater>oned_gk
All-Star
31135 Points
6361 Posts
Re: Dropdown inside a repeater
Nov 01, 2012 07:50 AM|LINK
Your ddl not in item or alternate, but in header
You have find the control with if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
Move the ddl to item & alternate template or use if (e.Item.ItemType = ListItemType.Header)
.net_junkie
Member
297 Points
825 Posts
Re: Dropdown inside a repeater
Nov 01, 2012 07:53 AM|LINK
I have already checked for it you can see my code above
oned_gk
All-Star
31135 Points
6361 Posts
Re: Dropdown inside a repeater
Nov 01, 2012 07:56 AM|LINK
your control inside headertemplate, not item/alternate template
<HeaderTemplate> <table> <tr> <td> <asp:DropDownList ID="DropDownList8" runat="server"> <asp:ListItem>Select</asp:ListItem> <asp:ListItem>Left</asp:ListItem> <asp:ListItem>Right</asp:ListItem> <asp:ListItem>SubString</asp:ListItem> </asp:DropDownList> <asp:DropDownList ID="DropDownList7" runat="server"> <asp:ListItem>1</asp:ListItem> <asp:ListItem>2</asp:ListItem> <asp:ListItem>3</asp:ListItem> </asp:DropDownList> <asp:DropDownList ID="DropDownList1" runat="server"> </asp:DropDownList> <asp:DropDownList ID="DropDownList2" runat="server"> </asp:DropDownList> <asp:Button ID="Button1" runat="server" Text="Button" /> </td> </tr> </table> </HeaderTemplate>See below
<ItemTemplate> <asp:DropDownList id="DropDownList1" runat="server" /> </ItemTemplate><AlternatingItemTemplate> <asp:DropDownList id="DropDownList1" runat="server" /> </AlternatingItemTemplate>.net_junkie
Member
297 Points
825 Posts
Re: Dropdown inside a repeater
Nov 01, 2012 09:24 AM|LINK
when i use if (e.Item.ItemType == ListItemType.Header) i am unable to fill the DDL as e.Item.ItemType is item and ListItemType.Header is header so the breakpoint is skipping the code and DDL is empty.
oned_gk
All-Star
31135 Points
6361 Posts
Re: Dropdown inside a repeater
Nov 01, 2012 04:40 PM|LINK