All,
I am trying to create a ReorderList in the codebehind for a page and am having a rediculous amount of trouble. When I set AllowReorder to 'false' the page displays what it should, but when i set AllowReorder to 'true' I get "Object reference not set to an instance of an object. " on the line where I am doing the databinding. I am using an SqlDataAdapter which implements both SelectCommand and UpdateCommand
This is my first time trying to set one of these up, so i think there is a good chance that I am missing something simple. I am copying and pasting in my code if that helps.
---begin code-----
1using System;2using System.Data;3using System.Configuration;4using System.Web;5using System.Web.Security;6using System.Web.UI;7using System.Web.UI.WebControls;8using System.Web.UI.WebControls.WebParts;9using System.Web.UI.HtmlControls;10using AjaxControlToolkit;11using System.Text;12using System.Data.SqlClient;1314public partialclass _Default : System.Web.UI.Page15{16protected void Page_Load(object sender, EventArgs e)17 {18 SqlConnection conn =new SqlConnection(ConfigurationManager.ConnectionStrings["GLISurveyGenerator_3"].ConnectionString);19 SqlDataAdapter dataadapter =new SqlDataAdapter();2021 SqlCommand selectcommand =new SqlCommand();22 selectcommand.CommandText="spGetPagesForSurvey";23 selectcommand.CommandType = CommandType.StoredProcedure;24 selectcommand.Parameters.Add("@dotnet.itags.org.SurveyID", SqlDbType.Int, 32).Value = 1;25 selectcommand.Connection = conn;2627 SqlCommand updatecommand =new SqlCommand();28 updatecommand.CommandText ="spUpdatePagesForSurvey";29 updatecommand.CommandType = CommandType.StoredProcedure;30 updatecommand.Parameters.Add("@dotnet.itags.org.SurveyPageID", SqlDbType.Int, 32);31 updatecommand.Parameters.Add("@dotnet.itags.org.SurveyPageNumber", SqlDbType.Int, 32);32 updatecommand.Connection = conn;3334 dataadapter.SelectCommand = selectcommand;35 dataadapter.UpdateCommand = updatecommand;3637 DataSet ds1 =new DataSet();3839 dataadapter.Fill(ds1);4041 ReorderList reorderlist =new ReorderList();42 reorderlist.ID ="RL1";43 reorderlist.AllowReorder =true;44 reorderlist.PostBackOnReorder =true;45 reorderlist.EnableViewState =false;46 reorderlist.ShowInsertItem =false;47 reorderlist.ItemTemplate =new pagereorderitemtemplate();48 reorderlist.ReorderTemplate =new pagereorderreorderitemtemplate();49 reorderlist.DragHandleTemplate =new pagereorderhandletemplate();50 reorderlist.EmptyListTemplate =new pagereorderemptytemplate();51 reorderlist.DataKeyField ="SurveyPageID";52 reorderlist.SortOrderField ="SurveyPageNumber";53 reorderlist.ShowInsertItem =false;5455 reorderlist.DataSource = ds1;56 reorderlist.DataBind();575859 contentholder.Controls.Add(reorderlist);60 }6162void reorderlist_UpdateCommand(object sender, ReorderListCommandEventArgs e)63 {64throw new Exception("The method or operation is not implemented.");65 }6667private class pagereorderitemtemplate : ITemplate68 {69public void InstantiateIn(System.Web.UI.Control container)70 {71 Literal lc =new Literal();72 lc.DataBinding +=new EventHandler(lc_DataBinding);73 container.Controls.Add(lc);74 }7576void lc_DataBinding(object sender, EventArgs e)77 {78 Literal lc;79 lc = (Literal)sender;80 ReorderListItem item = (ReorderListItem)lc.NamingContainer;81string dataitem = DataBinder.Eval(item.DataItem,"SurveyPageTitle").ToString();82 lc.Text = dataitem;83 }84 }8586private class pagereorderreorderitemtemplate : ITemplate87 {88public void InstantiateIn(System.Web.UI.Control container)89 {90 Literal lc =new Literal();91 lc.Text ="test2";92 container.Controls.Add(lc);93 }94 }9596private class pagereorderhandletemplate : ITemplate97 {98public void InstantiateIn(System.Web.UI.Control container)99 {100 Literal lc =new Literal();101 lc.Text ="| |";102 container.Controls.Add(lc);103 }104 }105106private class pagereorderemptytemplate : ITemplate107 {108public void InstantiateIn(System.Web.UI.Control container)109 {110 Literal lc =new Literal();111 lc.Text ="empty";112 container.Controls.Add(lc);113 }114 }115}
--end code--
I know most of the templates don't contain all that they should, I just wanted to put something in them so they at least existed. If anyone has any suggestions on how I can get around this error, I would greatly appreciate it.
-madrak
I have been able to pin down the error a little further. The reorderlist works with an sqldatasource that is created in the .aspx page using the following code
1"SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:GLISurveyGenerator_3 %>"2 SelectCommand="SELECT [SurveyPageID], [SurveyPageTitle], [SurveyPageNumber] FROM [tblSurveyPages] WHERE ([SurveyID] = @.SurveyID) order by [SurveyPageNumber]" UpdateCommand="Update [tblSurveyPages] set [SurveyPageNumber] = @.SurveyPageNumber, [SurveyPageTitle] = @.SurveyPageTitle where [SurveyPageID] = @.SurveyPageID">34 "1" Name="SurveyID" Type="Int32">567 "SurveyPageID" Type="Int32">8 "SurvePageTitle" Type="Int32">9 "SurveyPageNumber" Type="Int32">1011
but does not work with the sqldatasource as created in the prior post, anyone have any ideas?
Hi,
I removed reorderlist.DataBind(); and add page.DataBind();. Now I am able to display the data, but unable to reorder the items in the list
- narendra
Hi,
I have the same problem :(
Have anyone solved it?