Ms_ Dev

Ms_ Dev

  • NA
  • 236
  • 92.1k

Item doesnot exist in current context.

Feb 8 2017 1:10 AM
Hi.
 
I have the following code.
  1. private void GetItemsPageWise(int pageIndex)  
  2.        {  
  3.            string conString = ConfigurationManager.ConnectionStrings["FileStoreEntities"].ConnectionString;  
  4.            using (SqlConnection con = new SqlConnection(conString))  
  5.            {  
  6.                using (SqlCommand cmd = new SqlCommand("GetItems", con))  
  7.                {  
  8.                    cmd.CommandType = CommandType.StoredProcedure;  
  9.                    cmd.Parameters.AddWithValue("@PageIndex", pageIndex);  
  10.                    cmd.Parameters.AddWithValue("@PageSize"int.Parse(itemddlPageSize.SelectedValue));  
  11.                    cmd.Parameters.Add("@RecordCount", SqlDbType.Int, 4);  
  12.                    cmd.Parameters["@RecordCount"].Direction = ParameterDirection.Output;  
  13.                    con.Open();  
  14.                    IDataReader idr = cmd.ExecuteReader();  
  15.                    ItemView.DataSource = idr;  
  16.                    ItemView.DataBind();  
  17.                    idr.Close();  
  18.                    con.Close();  
  19.                    int recordCount = Convert.ToInt32(cmd.Parameters["@RecordCount"].Value);  
  20.                    this.PopulatePager(recordCount, pageIndex);  
  21.                }  
  22.            }  
  23.        }  
 and the aspx as -
 
  1. <form id="form1" runat="server">  
  2.     <div>  
  3.         PageSize:  
  4.         <asp:DropDownList ID="itemddlPageSize" runat="server" AutoPostBack="true" OnSelectedIndexChanged="PageSize_Changed">  
  5.             <asp:ListItem Text="10" Value="10" />  
  6.             <asp:ListItem Text="25" Value="25" />  
  7.             <asp:ListItem Text="50" Value="50" />  
  8.         </asp:DropDownList>  
  9.         <hr />  
  10.         <asp:GridView ID="ItemView" runat="server" AutoGenerateColumns="False">  
  11.             <Columns>  
  12.                 <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" />  
  13.                 <asp:BoundField DataField="Name" HeaderText="Name" />  
  14.                 <asp:BoundField DataField="Cost" HeaderText="Cost" />  
  15.                 <asp:BoundField DataField="Image" HeaderText="Image" />  
  16.                 <asp:BoundField DataField="Description" HeaderText="Description" />  
  17.                 <asp:BoundField DataField="AddedBy" HeaderText="AddedBy" />  
  18.             </Columns>  
  19.         </asp:GridView>  
I am getting error for Gridview, Dropdown and Repeater. it is coming  as item dowsnot exist in current context.
 
PLease help to resolve.
 
Thanks. 

Answers (1)