• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 808
  • Last Modified:

C# Dataset Custom Paging Errors????

How do I get this code to page data correctly?
Is there anything missing below???
There are two sets of navigation buttons, just for testing I was trying to see which set would work best.....

Please help!!!!!!!!!!!!

<%@ Page language="c#" Codebehind="Appl.aspx.cs" AutoEventWireup="false" Inherits="Appl.WebForm" Trace ="false" debug="true"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
      <HEAD>
            <title>WebForm1</title>
            <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
            <meta content="C#" name="CODE_LANGUAGE">
            <meta content="JavaScript" name="vs_defaultClientScript">
            <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
      </HEAD>
      <body bottomMargin="5" topMargin="5" MS_POSITIONING="GridLayout">
            <form id="Form1" method="post" runat="server">
                  <TABLE id="Table1" style="Z-INDEX: 101; LEFT: 16px; WIDTH: 936px; POSITION: absolute; TOP: 8px; HEIGHT: 310px"
                        borderColor="#deba84" cellSpacing="1" borderColorDark="#deba84" cellPadding="1" width="936"
                        border="1">
                        <TR>
                              <TD style="WIDTH: 745px; HEIGHT: 69px" align="center" bgColor="#4a3c8c" colSpan="4"
                                    rowSpan="1"><STRONG><FONT style="BACKGROUND-COLOR: transparent" color="#ffffff" size="4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                Multiple Order Waveplate Inventory</FONT></STRONG></TD>
                        </TR>
                        <TR>
                              <TD style="WIDTH: 146px; HEIGHT: 43px">
                                    <P>Nominal Retardance
                                          <asp:textbox id="DR" runat="server" Width="80px">0</asp:textbox></P>
                              </TD>
                              <TD style="WIDTH: 195px; HEIGHT: 43px">
                                    <P>Retardance Tolerance
                                          <asp:textbox id="DRST" runat="server" Width="73px">0</asp:textbox></P>
                              </TD>
                              <TD style="WIDTH: 183px; HEIGHT: 43px">
                                    <P>&nbsp;Diameter
                                          <asp:textbox id="Diameter" runat="server" Width="64px">0</asp:textbox></P>
                                    <P>Wavelength
                                          <asp:textbox id="DL" runat="server" Width="79px">0</asp:textbox></P>
                              </TD>
                              <TD style="WIDTH: 123px; HEIGHT: 43px">
                                    <P>Temperature
                                          <asp:textbox id="DT" runat="server" Width="81px">0</asp:textbox>&nbsp;</P>
                              </TD>
                        </TR>
                        <TR>
                              <TD id="MMMMMMM" style="WIDTH: 146px; HEIGHT: 10px" vAlign="baseline" width="146" runat="server">&nbsp;&nbsp;</TD>
                              <TD style="WIDTH: 195px; HEIGHT: 10px" vAlign="baseline" width="195" runat="server">&nbsp;+/-<asp:textbox id="MRST" runat="server" Width="168px">0</asp:textbox></TD>
                              <td style="WIDTH: 183px; HEIGHT: 10px">&nbsp;
                                    <asp:textbox id="MR" runat="server" Width="152px" Visible="False">0</asp:textbox></td>
                              </TD>
                              <TD id="TextBox1" style="WIDTH: 123px; HEIGHT: 10px" width="123" runat="server">&nbsp;</TD>
                        </TR>
                        <TR>
                              <TD style="WIDTH: 146px; HEIGHT: 23px"><asp:textbox id="TI" runat="server" Visible="False">0</asp:textbox></TD>
                              <TD style="WIDTH: 195px; HEIGHT: 23px"><asp:textbox id="Eq1" runat="server" Width="88px" AutoPostBack="True">0</asp:textbox><asp:textbox id="Eq2" runat="server" Width="88px">0</asp:textbox></TD>
                              <TD style="WIDTH: 183px; HEIGHT: 23px"></TD>
                              <TD style="WIDTH: 123px; HEIGHT: 23px">&nbsp;
                              </TD>
                        </TR>
                        <TR>
                              <TD style="WIDTH: 146px; HEIGHT: 28px">
                                    <P>&nbsp;</P>
                              </TD>
                              <TD style="WIDTH: 195px; HEIGHT: 28px"><asp:button id="QueryMe" runat="server" Text="QueryMe!"></asp:button></TD>
                              <TD style="WIDTH: 183px; HEIGHT: 28px">&nbsp;<asp:button id="BCal" runat="server" Width="96px" Text="Equate"></asp:button></TD>
                              <TD style="WIDTH: 123px; HEIGHT: 28px" colSpan="1" rowSpan="1"></TD>
                        </TR>
                        <TR>
                              <TD background="#deba84" bgColor="#deba84" colSpan="6"><asp:textbox id="Wavelength" runat="server" Width="64px" Visible="False">0</asp:textbox><asp:textbox id="Ret1" runat="server" Width="80px" Visible="False">0</asp:textbox><asp:textbox id="Tol1" runat="server" Width="56px" Visible="False">0</asp:textbox><asp:textbox id="dd" runat="server" Width="55px" Visible="False">0</asp:textbox><asp:textbox id="sT" runat="server" Width="64px" Visible="False">0</asp:textbox><asp:textbox id="d0" runat="server" Width="62px" Visible="False">0</asp:textbox><asp:textbox id="ML" runat="server" Width="68px" Visible="False">.6328</asp:textbox><asp:textbox id="cte" runat="server" Width="72px" Visible="False">1.377E-5</asp:textbox><asp:textbox id="dd0" runat="server" Width="60px" Visible="False">0</asp:textbox><asp:textbox id="MT" runat="server" Width="83px" Visible="False">21</asp:textbox><asp:label id="L1" runat="server" Width="72px"></asp:label><asp:textbox id="snD" runat="server" Width="62px" Visible="False">0</asp:textbox><asp:textbox id="dy" runat="server" Width="72px" Visible="False">0</asp:textbox><asp:textbox id="TBox" runat="server" Width="72px" Visible="False">1000</asp:textbox><asp:textbox id="snM" runat="server" Width="64px" Visible="False">0</asp:textbox><asp:button id="CalcSql" runat="server" Width="57px" Text="Calculate" Visible="False"></asp:button></TD>
                        </TR>
                        <tr>
                              <TD><asp:label id="LabelC" runat="server"></asp:label></TD>
                              <TD>
                                    <asp:Button id="frst" runat="server" Text="first"></asp:Button>
                                    <asp:Button id="prev" runat="server" Text="previous"></asp:Button>&nbsp;
                                    <asp:Button id="nxt" runat="server" Text="next"></asp:Button>
                                    <asp:Button id="las" runat="server" Text="last"></asp:Button></TD>
                              <td><asp:linkbutton id="FIRST" runat="server" Text="FIRST" Enabled="true">FIRST</asp:linkbutton>
                                    <asp:linkbutton id="PREVIOUS" runat="server" Text="PREVIOUS">PREVIOUS</asp:linkbutton>
                                    <asp:linkbutton id="NEXT" runat="server">NEXT</asp:linkbutton>
                                    <asp:linkbutton id="LAST" runat="server" Text="LAST">LAST</asp:linkbutton></td>
                        </tr>
                  </TABLE>
                  <asp:datagrid id=DGrid style="Z-INDEX: 102; LEFT: 16px; POSITION: absolute; TOP: 320px" runat="server" Width="882px" DataMember="DTable2" DataSource="<%# DataS2 %>" AllowCustomPaging="True" CellPadding="3" BackColor="#DEBA84" BorderWidth="1px" CellSpacing="2" BorderStyle="None" BorderColor="#DEBA84" AllowSorting="True" AllowPaging="True" AutoGenerateColumns="False" OnUpdateCommand="OnUpdate_Click" OnCancelCommand="CancelIt" OnEditCommand="Edit_Click" Height="478px" PageSize="25" OnPageIndexChanged="DGrid_PageIndexChanged">
                        <SelectedItemStyle Font-Bold="True" ForeColor="Silver" BackColor="#738A9C"></SelectedItemStyle>
                        <EditItemStyle Font-Bold="True" BackColor="Gray"></EditItemStyle>
                        <AlternatingItemStyle BackColor="#F7F7F7"></AlternatingItemStyle>
                        <ItemStyle ForeColor="#4A3C8C" BackColor="#E7E7FF"></ItemStyle>
                        <HeaderStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#4A3C8C"></HeaderStyle>
                        <FooterStyle ForeColor="#4A3C8C" BackColor="#B5C7DE"></FooterStyle>
                        <Columns>
                              <asp:EditCommandColumn ButtonType="PushButton" UpdateText="Update" CancelText="Cancel" EditText="Reserve"></asp:EditCommandColumn>
                              <asp:BoundColumn DataField="Inventory_Status" SortExpression="Inventory_Status" HeaderText="Inventory_Status"></asp:BoundColumn>
                              <asp:BoundColumn DataField="Part_Key" SortExpression="Part_Key" ReadOnly="True" HeaderText="Part_Key"></asp:BoundColumn>
                              <asp:BoundColumn DataField="Inventory_Type" SortExpression="Inventory_Type" ReadOnly="True" HeaderText="Inventory_Type"></asp:BoundColumn>
                              <asp:BoundColumn DataField="Operator_Name" SortExpression="Operator_Name" ReadOnly="True" HeaderText="Operator_Name"></asp:BoundColumn>
                              <asp:BoundColumn DataField="Diameter" SortExpression="Diameter" ReadOnly="True" HeaderText="Diameter"></asp:BoundColumn>
                              <asp:BoundColumn DataField="Retardation" SortExpression="Retardation" ReadOnly="True" HeaderText="Retardation"></asp:BoundColumn>
                              <asp:BoundColumn DataField="Physical_Location" SortExpression="Physical_Location" ReadOnly="True"
                                    HeaderText="Physical_Location"></asp:BoundColumn>
                              <asp:BoundColumn DataField="Retardation_Dec" SortExpression="Part_Key" ReadOnly="True" HeaderText="Retardation_Dec"></asp:BoundColumn>
                        </Columns>
                        <PagerStyle Visible="False" NextPageText="Nex" PrevPageText="Prev" HorizontalAlign="Right" ForeColor="#4A3C8C"
                              Position="TopAndBottom" BackColor="#E7E7FF"></PagerStyle>
                  </asp:datagrid></form>
      </body>
</HTML>



+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Configuration;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Diagnostics;
using System.Text;
using System.Xml;
using System.Configuration;

//using System.Reflection;



namespace Appl
{
      /// <summary>
      /// Summary description for WebForm1.
      /// </summary>
      public class WebForm : System.Web.UI.Page
      {
            protected System.Web.UI.WebControls.Button B1;
            protected System.Web.UI.WebControls.TextBox Ret2;
            protected System.Web.UI.WebControls.TextBox Tol;
            protected System.Web.UI.WebControls.Button B2;
            protected System.Web.UI.WebControls.TextBox Diamet;
            protected System.Web.UI.WebControls.Button QueryM;
            protected System.Web.UI.HtmlControls.HtmlTableCell TD1;
            protected System.Data.SqlClient.SqlCommand sqlCommand1;
            protected System.Web.UI.WebControls.TextBox TextBox4;
            protected System.Data.SqlClient.SqlCommand sqlC;
            protected System.Data.SqlClient.SqlConnection Conn;
            protected System.Data.DataRow DRow;
            protected System.Data.DataColumn Dcol;
            protected System.Collections.ArrayList ArL;
            protected System.Data.SqlClient.SqlConnection sqlConnection2;
            protected System.Data.SqlClient.SqlCommand sqlCo;
      protected System.Data.SqlClient.SqlCommand sqlC2;
            protected System.Web.UI.WebControls.TextBox Retardation;
            protected System.Data.DataSet Ds;
            protected System.Web.UI.WebControls.Button QueryMe;
            protected System.Web.UI.WebControls.DataGrid DGrid;
            protected System.Data.DataTable DTabl;
            protected System.Data.DataSet Dset;
            protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
            protected System.Data.SqlClient.SqlDataAdapter DataA;
            
            protected System.Web.UI.WebControls.Button BCal;
            protected System.Web.UI.HtmlControls.HtmlTableCell MMMMMMM;
            protected System.Web.UI.WebControls.TextBox MR;
            protected System.Web.UI.WebControls.TextBox MRST;
            protected System.Web.UI.WebControls.CheckBox ck;
            protected System.Data.SqlClient.SqlCommand sqlCommand2;
            protected System.Web.UI.WebControls.Label L;
            protected System.Web.UI.WebControls.TemplateColumn CheckBoxColumn;
            protected ArrayList bookidlist = new ArrayList();
            protected System.Web.UI.WebControls.TextBox DRST;
            protected System.Web.UI.WebControls.TextBox Eq1;
            protected System.Web.UI.WebControls.TextBox Eq2;
            protected System.Web.UI.WebControls.TextBox Diameter;
            protected System.Web.UI.HtmlControls.HtmlTableCell TextBox1;
            protected System.Web.UI.WebControls.TextBox DT;
            protected System.Web.UI.WebControls.TextBox DL;
            protected System.Web.UI.WebControls.Button CalcSql;
            protected System.Web.UI.WebControls.TextBox TBox;
            protected System.Web.UI.WebControls.TextBox dy;
            protected System.Web.UI.WebControls.TextBox snD;
            protected System.Web.UI.WebControls.Label L1;
            protected System.Web.UI.WebControls.TextBox MT;
            protected System.Web.UI.WebControls.TextBox dd0;
            protected System.Web.UI.WebControls.TextBox cte;
            protected System.Web.UI.WebControls.TextBox ML;
            protected System.Web.UI.WebControls.TextBox d0;
            protected System.Web.UI.WebControls.TextBox dd;
            protected System.Web.UI.WebControls.TextBox Tol1;
            protected System.Web.UI.WebControls.TextBox Wavelength;
            protected System.Web.UI.WebControls.TextBox sT;
            protected System.Web.UI.WebControls.TextBox Ret1;
            protected System.Web.UI.WebControls.TextBox snM;
            protected System.Web.UI.WebControls.TextBox DR;
            protected System.Web.UI.WebControls.TextBox TI;
            protected Appl.DSet2 DSet2;
            protected System.Data.DataTable DTable;
            protected System.Data.DataSet DataS2;
            protected System.Data.DataTable DTable2;
            protected System.Web.UI.WebControls.LinkButton PREVIOUS;
            protected System.Web.UI.WebControls.LinkButton FIRST;
            protected System.Web.UI.WebControls.LinkButton LAST;

            //protected System.Web.UI.WebControls.LinkButton FIRST;
            //protected System.Web.UI.WebControls.Button NEXT;
            //protected System.Web.UI.WebControls.LinkButton LAST;
            public int CurrentPage;
            //protected Prototype_2.Dset Dset;
            /*static DataGrid DGrid2 = new DataGrid();
            static int PageSize = 30;
            static int TPages = 0;
            static int CPage = 0;
            
            static DataTable Waveplate;*/
            static int pageSize = 30;
            static int TPages = 0;
            static int CPage = 0;
            static string fvPart = "";
            static string lvPart = "";
      static string LastRecord ="";
            protected System.Web.UI.WebControls.Label LabelC;
            protected System.Web.UI.WebControls.Button frst;
            protected System.Web.UI.WebControls.Button las;
            protected System.Web.UI.WebControls.Button prev;
            protected System.Web.UI.WebControls.LinkButton NEXT;
            protected System.Web.UI.WebControls.Button nxt;


            
            //static SqlConnection SqlCon = new SqlConnection("DataSource=VLOC-TRN-SQL; Integrated Security=SSPI;Initial Catalog=Waveplate");
            //static SQLDataAdapter DataA= new SqlDataAdapter("",Waveplate);
            //static SQLCommand sqlCo = DataA.SelectCommand;

            
            //protected Prototype_2.Dset Dset;
            //protected System.Configuration.ConfigurationSettings.AppSettings appSettings;
            //protected System.Configuration.ConfigurationSettings.GetConfig appSettings;
            protected System.Data.DataTable DTab;      

            
            private void Page_Load(object sender, System.EventArgs e)
            {

DGrid.PageIndexChanged += new DataGridPageChangedEventHandler(this.DGrid_PageIndexChanged);
                  
                  FIRST.Click += new System.EventHandler(this.first_Click);

NEXT.Click += new System.EventHandler(this.Next_OnClick);

PREVIOUS.Click += new System.EventHandler(this.prev_Click);
LAST.Click += new System.EventHandler(this.last_Click);


                  frst.Click += new System.EventHandler(this.NavigationButtonClick);
                  prev.Click += new System.EventHandler(this.NavigationButtonClick);
                  nxt.Click += new System.EventHandler(this.NavigationButtonClick);
                  las.Click += new System.EventHandler(this.NavigationButtonClick);
                  if(!IsPostBack)
                  {
                  
                        
                        
                        CurrentPage = 0;

            
                        //DGrid_PageIndexChanged += new DataGridPageChangedEventHandler(this.PageIndexChanged);
                        //DGrid.DataBind();
                  }       
                  
            }
            

            //#region Web Form Designer generated code
            override protected void OnInit(EventArgs e)
            {
                  //
                  // CODEGEN: This call is required by the ASP.NET Web Form Designer.
                  //
                  InitializeComponent();
                  base.OnInit(e);
            }
            
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            ///

      
            protected void InitializeComponent()
            {    
                  System.Configuration.AppSettingsReader configurationAppSettings = new System.Configuration.AppSettingsReader();
                  this.Conn = new System.Data.SqlClient.SqlConnection();
                  this.sqlCo = new System.Data.SqlClient.SqlCommand();
                  this.DTable = new System.Data.DataTable();
                  this.DataA = new System.Data.SqlClient.SqlDataAdapter();
                  this.DataS2 = new System.Data.DataSet();
                  this.DTable2 = new System.Data.DataTable();
                  this.DSet2 = new Appl.DSet2();
                  ((System.ComponentModel.ISupportInitialize)(this.DTable)).BeginInit();
                  ((System.ComponentModel.ISupportInitialize)(this.DataS2)).BeginInit();
                  ((System.ComponentModel.ISupportInitialize)(this.DTable2)).BeginInit();
                  ((System.ComponentModel.ISupportInitialize)(this.DSet2)).BeginInit();
                  this.QueryMe.DataBinding += new System.EventHandler(this.QueryMe_Click);
                  this.QueryMe.Click += new System.EventHandler(this.QueryMe_Click);
                  this.BCal.Click += new System.EventHandler(this.BCal_Click);
                  this.DGrid.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DGrid_PageIndexChanged);
                  this.DGrid.SelectedIndexChanged += new System.EventHandler(this.btnUpdate_Click);
                  //
                  // Conn
                  //
                  this.Conn.ConnectionString = ((string)(configurationAppSettings.GetValue("Conn.ConnectionString", typeof(string))));
                  //
                  // sqlCo
                  //
                  this.sqlCo.CommandText = ((string)(configurationAppSettings.GetValue("sqlCo.CommandText", typeof(string))));
                  this.sqlCo.CommandTimeout = ((int)(configurationAppSettings.GetValue("sqlCo.CommandTimeout", typeof(int))));
                  this.sqlCo.Connection = this.Conn;
                  //
                  // DTable
                  //
                  this.DTable.Namespace = ((string)(configurationAppSettings.GetValue("DTable.Namespace", typeof(string))));
                  this.DTable.TableName = ((string)(configurationAppSettings.GetValue("DTable.TableName", typeof(string))));
                  //
                  // DataA
                  //
                  this.DataA.AcceptChangesDuringFill = ((bool)(configurationAppSettings.GetValue("DataA.AcceptChangesDuringFill", typeof(bool))));
                  this.DataA.ContinueUpdateOnError = true;
                  this.DataA.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
                                                                                                                                          new System.Data.Common.DataTableMapping("Table", "Waveplate", new System.Data.Common.DataColumnMapping[] {
                                                                                                                                                                                                                                                                                                             new System.Data.Common.DataColumnMapping("Part_Key", "Part_Key"),
                                                                                                                                                                                                                                                                                                             new System.Data.Common.DataColumnMapping("Physical_Location", "Physical_Location"),
                                                                                                                                                                                                                                                                                                             new System.Data.Common.DataColumnMapping("Retardation", "Retardation"),
                                                                                                                                                                                                                                                                                                             new System.Data.Common.DataColumnMapping("Diameter", "Diameter"),
                                                                                                                                                                                                                                                                                                             new System.Data.Common.DataColumnMapping("Retardation_Dec", "Retardation_Dec")})});
                  //
                  // DataS2
                  //
                  this.DataS2.DataSetName = ((string)(configurationAppSettings.GetValue("DataS2.DataSetName", typeof(string))));
                  this.DataS2.Locale = new System.Globalization.CultureInfo("en-US");
                  this.DataS2.Namespace = ((string)(configurationAppSettings.GetValue("DataS2.Namespace", typeof(string))));
                  this.DataS2.Tables.AddRange(new System.Data.DataTable[] {
                                                                                                            this.DTable2});
                  //
                  // DTable2
                  //
                  this.DTable2.Namespace = ((string)(configurationAppSettings.GetValue("DTable2.Namespace", typeof(string))));
                  this.DTable2.TableName = ((string)(configurationAppSettings.GetValue("DTable2.TableName", typeof(string))));
                  //
                  // DSet2
                  //
                  this.DSet2.DataSetName = "DSet2";
                  this.DSet2.Locale = new System.Globalization.CultureInfo("en-US");
                  this.Load += new System.EventHandler(this.Page_Load);
                  this.PreRender += new System.EventHandler(this.Page_Load);
                  ((System.ComponentModel.ISupportInitialize)(this.DTable)).EndInit();
                  ((System.ComponentModel.ISupportInitialize)(this.DataS2)).EndInit();
                  ((System.ComponentModel.ISupportInitialize)(this.DTable2)).EndInit();
                  ((System.ComponentModel.ISupportInitialize)(this.DSet2)).EndInit();

            }


            public void Calc_Click(Object Sender, EventArgs e)
            {
            
                  
                  Eq1.Text = (double.Parse(TI.Text) + double.Parse(DRST.Text)).ToString();
                  Eq2.Text = (double.Parse(TI.Text) - double.Parse(DRST.Text)).ToString();

            }

            public void Add_Click (object sender, EventArgs e)
            {
                  Eq1.Text = (double.Parse(Ret1.Text) + double.Parse(Tol1.Text)).ToString();
                  
            }


            public void Add_Subtract (object sender, EventArgs e)
            {
                  Eq2.Text = (double.Parse(Ret2.Text) - double.Parse(Tol1.Text)).ToString();
            }

            public void interger (object sender, EventArgs el)
            {
                  int DefFrom = -1000000;
                  int DefTo = 100000000;
      

                  try
                  {

                        int F;
                        int T;
                        F = Eq1.Text.Trim().Length==0?DefFrom:int.Parse(Eq1.Text);
                        T = Eq2.Text.Trim().Length==0?DefTo:int.Parse(Eq2.Text);

                        //string sql = "select * from Waveplate";
                        //sql += "where  Retardation >" +From.ToString();
                        //sql += "and field2 <" +to.ToString();

                  }
                  catch (System.Exception e)
                  {
                        Response.Write(e.Message);
                  }
            }
            protected void QueryMe_Click(object sender, EventArgs e)
            {

                  int CIndex = 0;
                  int pageSize = 10;
                  
                  Conn.Open();
                        
                  //string LRecord = DSet2.Tables["Waveplate"].Rows[PageSize -1]["Part_Key"].ToString();
                  string sqlC  = "(select * from Waveplate where Retardation between " + Eq2.Text + " and " + Eq1.Text + " and Diameter = '" + Diameter.Text + "')order by Physical_Location";
//"(Select * from Waveplate where (Retardation between " + Eq2.Text + " and " + Eq1.Text + ")) and Diameter = '" + Diameter.Text + "') or ((Retardation between " + Eq1.Text + " and " + Eq2.Text + ")) and Diameter = '" + Diameter.Text + "')order by Physical_Location";
            
                  //string sqlC = "(select * from Waveplate where Retardation between " + Eq2.Text + " and " + Eq1.Text + " and Diameter = '" + Diameter.Text + "')";
                  //string sqlC = String.Format("(select * from Waveplate where Retardation between {0} and {1} and {2} = Diameter)", Eq1.Text, Eq2.Text , Diameter.Text) ;
                  
      



                  DataA = new System.Data.SqlClient.SqlDataAdapter(sqlC, Conn);
                        
                  //SqlCommand CommandText = Conn.CreateCommand();

                  //sqlC.Connection = Conn;
                  //string Q = "select * from Main_Wave_Inv (Retardation,Retardation)(@Ret1,@Ret2)";
                  //SqlCommand sqlCom = new SqlCommand(sqlC, Conn);
                  
                  //string SQ = System.Configuration.ConfigurationSettings.AppSettings("Conn");
                  DataTable DTable = new DataTable();
                  
                  //sqlC.CommandText = "Select * from Main_Wave_Inv, Conn"; //(Retardation, Retardation)(@Eq1,@Eq2)",Conn) ;
                  CIndex += pageSize;
                  
                  ViewState["CurrentPage"] = CurrentPage;
                  //ViewState[CurrentPage.ToString()] = DGrid.Items[0].Cells[0].Text;

                  DataA.Fill(DataS2, CIndex, CurrentPage, "Waveplate");
                  DGrid.DataSource = DataS2;
                  DGrid.DataMember = "Waveplate";
                  DataView MiDView = DataS2.Tables["Waveplate"].DefaultView;
                  int Rcount = MiDView.Table.Rows.Count;
                  LabelC.Text = Rcount.ToString();
                  ViewState["CurrentPage"] = CurrentPage;
                  //ViewState[CurrentPage.ToString()] = DGrid.Items[0].Cells[0].Text;
                  //DGrid.CurrentPageIndex = DGrid.Page;
                  //DataS["Timestamp"] = DateTime.Now.Date.ToLocalTime();
                  //DTable.Clear();
                  //DTable.Columns.Clear();
                  int RCount = DataS2.Tables["Waveplate"].Rows.Count;
                  //LabelC.Text = RCount.ToString();
                  
                  DataS2.Tables.Add();
                  DGrid.DataBind();
                  //Session["Waveplate"]= DataS2;
                  string LastRecord = DataS2.Tables["Waveplate"].Rows[Rcount -1]["Physical_Location"].ToString();
                  
                  DGrid.VirtualItemCount.ToString();
                  
                  //ViewState["LastKey"] = DGrid.DataKeys[DGrid.Items.Count];
                  //ViewState["FirstKey"] = DGrid.DataKeys[-1];
                  //int Physical_Location = Convert.ToInt32(ViewState["FirstKey"]);
                  //int Physical_Location = Convert.ToInt32(ViewState["LastKey"]);
            
                  //SqlDataAdapter DataA = new SqlDataAdapter("Select * from Waveplate", Conn);

                  //DataA.Fill(Dset,"Waveplate");
                  /*if (DGrid.Items.Count < DGrid.PageSize)
                  {
                        NEXT.Enabled = false;
                  
                  }

                  else
                  {
                        LAST.Enabled = false;

                  }*/

                  
                  Conn.Close();
            }                        


            



            //this.Dcol.DataType = MiSqlDReader.GetFieldType(i);
            //this.Dcol.ColumnName = MiSqlDReader.GetName(i);
            //this.Dset.Tables(Main_Waveplate_Inv).Columns.Add();
            //}
            //public System.Data.DataTable GetTable(System.Data.SqlClient.SqlDataReader Reader)
            //{
            //}
            //catch(System.Exception ex)
            //{
            // Response.Write(ex.Message);
                        
            //........Messagebox.Show(ex.Message);
      
            
            //#endregion
      
            //RcdCount = DS.Tables("pubs").Rows.Count.ToString()
            //totalCount=ds.Tables["People"].Rows.Count.ToString();
            
      
            
                  
            
            private void BCal_Click(object sender, EventArgs e)

            {
                  try
                  {

                        //snD.Text = (double.Parse(.0088641 + .000107057) * (DL.Text)^2+1.9893*(.000001/(DL.Text)^4)-(.00017175)*(DL.Text)^2-DT.Text*(.000001)*(1+DT.Text/900)*1.01+0.2*(DL.Text)*2;
                        double dr = Double.Parse(DR.Text);
                        double dl = Double.Parse(DL.Text);
                        double dt = Double.Parse(DT.Text);
                        double sn = Double.Parse(snD.Text);
                        double d = Double.Parse(d0.Text);
                        double s = Double.Parse(sT.Text);
                        double m = Double.Parse(MT.Text);
                        double dx = Double.Parse(dy.Text);
                        double ct = Double.Parse(cte.Text);
                        double sn2 = Double.Parse(snM.Text);      
                        double m1 = Double.Parse(ML.Text);
                        double m2 = Double.Parse(MR.Text);
                        double d1 = Double.Parse(dd0.Text);
                        double drs = Double.Parse(DRST.Text);
                        double d2 = Double.Parse(dd.Text);
                        double mrt = Double.Parse(MRST.Text);
 
                        //snD.Text = double.Parse(snD.Text).ToString();

                        //int z;
                        //z = 1000;
                        //TBox.Text = z.ToString();
                        //m1/z
                        //DL.Text = (double.Parse(Wavelength.Text) / double.Parse(TBox.Text)).ToString();
                        //sn = (.0088641 + 1.07057 * (.0001)/(dl * dl) + (1.9893 *.000001)/(dl*4*4) - .00017175*(dl*dl)-(dt) * .000001*1+dt/900*(1.01+0.2)*(dl*dl));                                                                                                                                                                                                                               
                        
                        //sn = (Double.Parse("8.8641E-03")+1.07057*(Double.Parse("1E-04")/(dl * dl)) + 1.9893*Math.Pow(Double.Parse("1E-06")/dl, 4) - Double.Parse("1.7175E-04")*dl*dl-dt*(Double.Parse("1E-06")*(1+dt/900)*(1.01+0.2*dl*dl)));  
                        
                        sn =8.8641*10e-4+1.07057*(10e-5/(Math.Pow(dl,2)))+1.9893*(10e-7/(Math.Pow(dl,4)))-1.7175*10e-5*(Math.Pow(dl,2))-dt*10e-7*(1+dt/900)*(1.01+0.2*(Math.Pow(dl,2)));
                        
                        d = (dr*dl)/sn;
                        //s = (dt-m);
                        s = (m-dt);
                        dx = d*(1+ct*s);
                        //sn2 = (Double.Parse("8.8641E-03") + 1.07057*(Double.Parse("1E-04")/(m1 * m1)) + 1.9893*Math.Pow(Double.Parse("1E-06")/m1, 4)- Double.Parse("1.7175E-04")*m1*m1-m * (Double.Parse("1E-06")*(1+m/900)*(1.01+0.2*m1*m1)));
                        
                        sn2 = 8.8641*10e-4+1.07057*(10e-5/(Math.Pow(m1,2)))+1.9893*(10e-7/(Math.Pow(m1,4)))-1.7175*10e-5*(Math.Pow(m1,2))-m*10e-7*(1+m/900)*(1.01+0.2*(Math.Pow(m1,2)));
                        
                        
                        m2 = (sn2*dx)/m1;
                        d1 = (drs*dl)/sn;
                        d2 = d1*(1+ct*s);
                        mrt = (sn2*d2)/m1;


                        //snD.Text = snD.Text.ToString();
                        //sT.Text = (double.Parse(MT.Text) - double.Parse(DT.Text)).ToString();

                        snD.Text = sn.ToString();
                        d0.Text =d.ToString();
                        dd.Text = d2.ToString();
                        DRST.Text = drs.ToString();
                        snM.Text = sn2.ToString();
                        MRST.Text = mrt.ToString();
                        dy.Text = dx.ToString();
                        sT.Text = s.ToString();
                        MR.Text = m2.ToString();
                        dd0.Text = d1.ToString();
                        //int DefFrom = -1000000;
                        Eq1.Text = (double.Parse(TI.Text) + double.Parse(DRST.Text)).ToString();
                        Eq2.Text = (double.Parse(TI.Text) - double.Parse(DRST.Text)).ToString();
                        TI.Text=MR.Text;
                  }



                  catch (FormatException ex)
                  
                  {

                        //ex.Message = "FormatException" + ex;
                        //MessageBox.Show("Message" + ex);\
                        Response.Write("Error Message is" + ex.ToString());
                        Response.Write(ex.Message);
                  }
                  
            }

            private void Conn_InfoMessage(object sender, System.Data.SqlClient.SqlInfoMessageEventArgs e)
            {
            
            }

            private void Eq1_TextChanged(object sender, System.EventArgs e)
            {
            
            }

            private void Button1_Click(object sender, System.EventArgs e)
            {
                  //Checkbox update function
                  //OleDbCommand c = new OleDbCommand("UPDATE Item SET Status='Loan'", con);
                  //con.Open();
                  //c.ExecuteNonQuery();
                  /*      string key = DGrid.DataKeys[e.Item.ItemIndex].ToString();

                        string Sq;
                        Sq = "Update [Waveplate]" +
                              "set Reserve_User =?, Reserve_User =?," +
                                    "Inventory_Status=?, Inventory_Status=R"+
                                    "where Part_Key =?, and Physical_Location=?";

                        SqlCommand SCom = new SqlCommand(Sq, Conn);
                        SqlParameterCollection CSql = SCom.Parameters;
                        CSql.Add("Inventory_Status", SqlDbType.Char);
                        CSql.Add ("Reserve_Time", SqlDbType.DateTime);
            

            DataA.Update(DataS, "Waveplate");
            DataS.AcceptChanges();*/
            }

            public void Edit_Click(Object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
            {
                  DGrid.EditItemIndex = e.Item.ItemIndex;
                  BindIt();

            }
            


            /*      public void DGrid_ItemDataBound(object sender,
                        System.Web.UI.WebControls.DataGridItemEventArgs e)
                  {
                        if(e.Item.ItemType == ListItemType.EditItem)
                        {
                              DataRowView drv = (DataRowView) e.Item.DataItem;
                              String currentgenre = drv["Inventory_Status"].ToString();
                              DropDownList ddl =
                                    (DropDownList) e.Item.FindControl("DropDownList1");
                              ddl.SelectedIndex =
                                    ddl.Items.IndexOf(ddl.Items.FindByText(currentgenre));
                        }
                  }
      */

            protected void OnUpdate_Click(Object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
            {


                  DateTime DT = DateTime.Now;
                  string ToDa = DT.ToString("mm/dd/yyyy hh:nn:ss");
                  string Inv;
                  //bool Discon=((CheckBox)e.Item.FindControl("Part_Key")).Checked;
                  string Key = DGrid.DataKeys[e.Item.ItemIndex].ToString();
                  TextBox box;
                  //DropDownList = box;
                  box = (TextBox)(e.Item.Cells[1].Controls[0]);
                  Inv=box.Text;
                  //Label L;
                  
                        
                        
                  
                  //ddl.SelectedIndex = ddl.Items.IndexOf(ddl.Items.FindByText(Inv));
                  
                  
            

                  
      
                  // Gets the value the TextBox control in the 7th column
                  //Convert.ToDateTime((e.Item.Cells[8].Controls[0]));
                  //Convert.ToDateTime(e.Item.Cells(8).Text);
                  //L.Text = ToDa;


                  ToDa = ToDa.ToString();
            
                  string Sq;
                  
                  Sq = "Update Waveplate set Inventory_Status=@Inventory_Status where Part_Key = @Part_Key";
           
                  //Reserve_Timestamp = "+"'GetDate()'"+
                  //Sq = "Update [Waveplate]" + "set Inventory_Status=@Inventory_Status"+
                  //"where Part_Key =@Part_Key";

                  SqlCommand SCom = new SqlCommand(Sq, Conn);
                  //SqlParameterCollection CSql = SCom.Parameters;

                  SCom.Parameters.Add("@Part_Key", SqlDbType.Char);
                  SCom.Parameters["@Part_Key"].Value=Key;


                  SCom.Parameters.Add("@Inventory_Status", SqlDbType.Char);
                  SCom.Parameters["@Inventory_Status"].Value=Inv;


                  //SCom.Parameters.Add("@Reserve_Time", SqlDbType.DateTime);
                  //SCom.Parameters["@Reserve_Time"].Value=ToDa;

                  SCom.Parameters["@Part_Key"].Value = DGrid.DataKeys[(int)e.Item.ItemIndex];
                  SCom.Connection.Open();
      
                  try
                  {
                        SCom.ExecuteNonQuery();
                        Response.Write ("<b></b><br>" + Sq);
                        DGrid.EditItemIndex = -1;
                  }
                  catch (SqlException E)
                  {
                        if (E.Number == 2627)
                              Response.Write("ERROR: ");
                        else
                              Response.Write ("ERROR: ");
                        

                  }

                  SCom.Connection.Close();

                  BindIt();
            }

      



            //DataA.Update(DataS, "Waveplate");
            //DataS.AcceptChanges();


            public void DGrid_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
            {
                  
                  DGrid.CurrentPageIndex = e.NewPageIndex;
                  
                  
                  DataBind();
            }
            public void CancelIt(Object sender, DataGridCommandEventArgs e)
            {
                  DGrid.EditItemIndex = -1;
                  BindIt();
            }
            protected void DGrid_Checked(object sender, System.EventArgs  e)
            {
                  /*      //CType(y.Item.ItemType = )

                              int Rcount = 0;
                              StringBuilder DGridMe = new StringBuilder();
                  

                              //int Part_Key =(int)DGrid.DataKeys[(int)e.ItemIndex];
                              //bool Reserved=((CheckBox)e.Item.FindControl("Reserved")).Checked;
              //CheckBox CBox = (ck) e.Item.FindControl("Inventory_Status");
                              //Binding CheckBind = new Binding("Check", DSet,"Waveplate.Inventory_Status");

            //ck.DataBindingsAdd(CheckBind);

                              //findout the selected item index and bindgrid again
                              //DGrid.EditItemIndex = (int)y.Item.ItemIndex;
                  

                              //CheckBox checkbx;
            
                              foreach (DataGridItem DGridItem in DGrid.Items)

                              {
                                    CheckBox Ccheck = (CheckBox)DGridItem.Cells[0].Controls[2];
                                    //DataRow ro;
      
                                    //TextBox t;


                                    t = (TextBox)DGridItem.Cells[2].Controls[0];
                                          //ck(e.Item.Cells[6].Controls[2]);
            

                                    //DataGridItem DGI = DGrid.Items[i].FindControl("Inventory_Status");
                                    //ck = (y.Item.FindControl());
                                    //CBox.Checked
                                    //bool CValu;
                                    //string K = DGrid.DataKeys[y.Item.ItemIndex].ToString();

                                    if(Ccheck.Checked == true)

                                    {


                                    Rcount++;
                                          Ccheck.Text = "Reserv";
            DGridMe.AppendFormat("CheckBoxes {0} were checked <br>", DGrid.DataKeys[DGridItem.ItemIndex].ToString());
                                    DGridMe.AppendFormat("Total number selected is: {0}", Rcount.ToString());
                  

                        
                                    }
                              }
            //DGridMe.AppendFormat("Total number selected is: {0}", Rcount.ToString());
                              DGridMe.Append("<hr>");
                              L1.Text = DGridMe.ToString();

            //DGridMe.AppendFormat("CheckBoxes {0} were checked <br>", DGrid.DataKeys[DGridItem.ItemIndex].ToString());
                              }
                        private void dd_TextChanged(object sender, System.EventArgs y)
                        {
                              //UpdateCommand.Parameters.Add("@ck", SqlDbType.VarChar, 99).Value = ck.Checked.ToString
                        /*<asp:TemplateColumn HeaderText="Reservation">
                                    <ItemTemplate><asp:Checkbox ID =ck Runat="server" Text=<%#DataBinder.Eval(Container.DataItem,"Inventory_Status")%>
                                    Checked ='<%#DataBinder.Eval(Container.DataItem,"Y")%>'></asp:Checkbox></asp:Checkbox></ItemTemplate></asp:TemplateColumn>*/

                  //if ck.Checked = DGrid.EditItemIndex = -1;
                  //DataBind();
            }

            public void btnUpdate_Click(object sender, System.EventArgs e)
            {
                  int i;
                  DataGridItem dgi;
                  int bookid;
                  TextBox TextBoxTitle;
                  CheckBox ChInv;
                  TextBox TextBoxPrice;
                  string Sq2;
                  
                  Sq2 = "Update Waveplate set Inventory_Status=@Inventory_Status where Part_Key =@Part_Key";
                  SqlCommand SCom2 = new SqlCommand(Sq2, Conn);
                  for(i = 0; i <= DGrid.Items.Count -1 ; i++)
                  {
                        dgi = DGrid.Items[i];
                        Label LabelBookId = (Label) dgi.Cells[0].Controls[1];
                        bookid = int.Parse(LabelBookId.Text);
                        TextBoxTitle = (TextBox) dgi.FindControl("TextBoxTitle");
                        ChInv = (CheckBox) dgi.FindControl("CheckBoxInStock");
                        TextBoxPrice = (TextBox) dgi.FindControl("TextBoxPrice");
                        //this.dcmdUpdateBooks.Parameters["@bookid"].Value = bookid;
                        //this.dcmdUpdateBooks.Parameters["@Title"].Value = TextBoxTitle.Text;
                        SCom2.Parameters["@Inventory_Status"].Value =
                              ChInv.Checked;
                        ChInv.Text = "R";
                        //this.dcmdUpdateBooks.Parameters["@Price"].Value =
                        float.Parse(TextBoxPrice.Text);
                        this.Conn.Open();
                        SCom2.ExecuteNonQuery();
                        this.Conn.Close();
                  }
            }
            public void BindIt()
            {
                  Conn.Open();
                        
                  
                  string sqlC = "(select Top 30 * from Waveplate where ((Retardation between " + Eq2.Text + " and " + Eq1.Text + ") or (Retardation between " + Eq1.Text + " and " + Eq2.Text + ")) and Diameter = '" + Diameter.Text + "')";
            
                  //string sqlC = "(select * from Waveplate where Retardation between " + Eq2.Text + " and " + Eq1.Text + " and Diameter = '" + Diameter.Text + "')";
                  //string sqlC = String.Format("(select * from Waveplate where Retardation between {0} and {1} and {2} = Diameter)", Eq1.Text, Eq2.Text , Diameter.Text) ;
                        
                  DataA = new System.Data.SqlClient.SqlDataAdapter(sqlC, Conn);
                        
                  //SqlCommand CommandText = Conn.CreateCommand();

                  //sqlC.Connection = Conn;
                  //string Q = "select * from Main_Wave_Inv (Retardation,Retardation)(@Ret1,@Ret2)";
                  //SqlCommand sqlCom = new SqlCommand(sqlC, Conn);
                  
                  //string SQ = System.Configuration.ConfigurationSettings.AppSettings("Conn");
                  DataTable DTable = new DataTable();
                  
                  //sqlC.CommandText = "Select * from Main_Wave_Inv, Conn"; //(Retardation, Retardation)(@Eq1,@Eq2)",Conn) ;
                  DataA.Fill(DataS2, "Waveplate");
                  DGrid.DataSource = DataS2;
                  DGrid.DataMember = "Waveplate";
                  
                        
                  DTable.Clear();
                  DTable.Columns.Clear();
                  
                  
                  DataS2.Tables.Add();
                  DGrid.DataBind();

            
                  //SqlDataAdapter DataA = new SqlDataAdapter("Select * from Waveplate", Conn);

                  //DataA.Fill(Dset,"Waveplate");
                        
                  
                  Conn.Close();
            }
            /*private void btnUp_Click(object sender, System.EventArgs e)
            {
                  int i;
                  DataGridItem dgi;
                  int bookid;
                  //Rest of declarations here

                  for(i = 0; i <= DGrid.Items.Count -1 ; i++)
                  {
                        dgi = DGrid.Items[i];
                        TableCell tc = dgi.Cells[0];
                        string s = dgi.Cells[0].Text;
                        Label LabelBookId = (Label) dgi.Cells[3].Controls[1];
                        bookid = int.Parse(LabelBookId.Text);
                        if (bookidlist.Contains(bookid))
                        {
                              // Update code here
                        }
                  }
            }
            protected void RowChanged( object sender, System.EventArgs e)
            {
                  DataGridItem dgi = (DataGridItem)(((Control)sender).NamingContainer);
                  Label bookidlabel = (Label) dgi.Cells[3].Controls[1];
                  int Part_Key = int.Parse(bookidlabel.Text);
                  if (!bookidlist.Contains(Part_Key))
                  {
                        bookidlist.Add(Part_Key);
                  }
            }*/
            public void ck_Click(object sender, System.EventArgs e)

            {

                  //if (ck.Checked)
                  //      Inventory_Status.

            
            }

            private void dy_TextChanged(object sender, System.EventArgs e)
            {
            
            }
            
            /*public static void GetData(string direction)
            {
                  sqlCo.Parameters.Clear();
            
                  switch(direction)
                  {

            
                  
      
                        case "Next":
                              sqlCo.CommandText = "(Select * from Waveplate where ((Retardation between " + Eq2.Text + " and " + Eq1.Text + ") or (Retardation between " + Eq1.Text + " and " + Eq2.Text + ")) and Diameter = '" + Diameter.Text + "')";
                  
                              sqlCo.Parameters.Add("@Part_Key",SqlDBType.Char,15).Value = lvPart;
                              break;



                        case "Previous":
                              sqCo.CommandText = "(Select * from Waveplate where ((Retardation between " + Eq2.Text + " and " + Eq1.Text + ") or (Retardation between " + Eq1.Text + " and " + Eq2.Text + ")) and Diameter = '" + Diameter.Text + "')";
                  
                              sqlCo.Parameters.Add("@Part_Key",SqlDBType.Char,15).Value = fvPart;
                              break;



                  }
            }*/

            private void DR_TextChanged(object sender, System.EventArgs e)
            {
            
            }


      
      
      



            public void prev_Click(object sender, System.EventArgs e)
            {
            
                  if
            
                        (DGrid.CurrentPageIndex > 0)
                  {
DGrid.CurrentPageIndex -=1;
                        DataBind( );


            
            
            
                  }
                  }
            public void last_Click(object sender, System.EventArgs e)
{
                  if (DGrid.CurrentPageIndex< DGrid.PageCount -1)
                  {
                        DGrid.CurrentPageIndex = DGrid.PageCount -1;
                        DataBind();
            
                  }
            }
            public void Next_OnClick(object sender, EventArgs e)
            {
                  if (DGrid.CurrentPageIndex < DGrid.PageCount -1)
                  {

                  
                  }
                  DGrid.CurrentPageIndex += 1;
                  sqlC.CommandText = "Select Top" +pageSize+" * from Waveplate"+
                        "where Physical_Location > @Physical_location Order By Physical_Location";
                  sqlC.Parameters.Add("@Physical_location", SqlDbType.Int, 4).Value = LastRecord;
            }

            public void first_Click(object sender, EventArgs e)
            {
                  if (DGrid.CurrentPageIndex <0)
                  {
                        DGrid.CurrentPageIndex = 0;

                  Bind();
                  }
            }

            private void NavigationButtonClick(object sender, System.EventArgs e)
            {
                  string direction = ((Button)sender).CommandName;

                  switch (direction.ToUpper())
                  {
                        case "frst" :
                              DGrid.CurrentPageIndex = 0;
                              break;
                        case "prev" :
                              DGrid.CurrentPageIndex =
                                    Math.Max(DGrid.CurrentPageIndex -1, 0);
                              break;
                        case "nxt" :
                              DGrid.CurrentPageIndex =
                                    Math.Min(DGrid.CurrentPageIndex + 1,
                                    DGrid.PageCount - 1);
                              
                              break;
                        case "las" :
                              DGrid.CurrentPageIndex = DGrid.PageCount - 1;
                              break;
                        default :
                              break;
                  }
                  
            }
            protected void Bind()

            {
            
                  int CIndex = 0;
                  int pageSize = 10;
                  
                  Conn.Open();
                        
                  //string LastRecord = DSet2.Tables["Waveplate"].Rows[pageSize -1]["Physical_Location"].ToString();
                  string sqlCo  = "(SELECT * From Waveplate where Physical_Location > "+LastRecord+") order by Physical_Location";
                  //DataA.SelectCommand.CommandText = sqlCo;
                  //DataS2.Tables["Waveplate"].Rows.Clear();
                  //sqlC2.Parameters.Add("@Physical_location", SqlDbType.Int, 4).Value = LastRecord;


                  
                  
                  //"(Select * from Waveplate where (Retardation between " + Eq2.Text + " and " + Eq1.Text + ")) and Diameter = '" + Diameter.Text + "') or ((Retardation between " + Eq1.Text + " and " + Eq2.Text + ")) and Diameter = '" + Diameter.Text + "')order by Physical_Location";
            
                  //string sqlC = "(select * from Waveplate where Retardation between " + Eq2.Text + " and " + Eq1.Text + " and Diameter = '" + Diameter.Text + "')";
                  //string sqlC = String.Format("(select * from Waveplate where Retardation between {0} and {1} and {2} = Diameter)", Eq1.Text, Eq2.Text , Diameter.Text) ;
                  
      



                  DataA = new System.Data.SqlClient.SqlDataAdapter(sqlCo, Conn);
                        
                  //SqlCommand CommandText = Conn.CreateCommand();

                  //sqlC.Connection = Conn;
                  //string Q = "select * from Main_Wave_Inv (Retardation,Retardation)(@Ret1,@Ret2)";
                  //SqlCommand sqlCom = new SqlCommand(sqlC, Conn);
                  
                  //string SQ = System.Configuration.ConfigurationSettings.AppSettings("Conn");
                  DataTable DTable = new DataTable();
                  
                  //sqlC.CommandText = "Select * from Main_Wave_Inv, Conn"; //(Retardation, Retardation)(@Eq1,@Eq2)",Conn) ;
                  CIndex += pageSize;
                  
                  ViewState["CurrentPage"] = CurrentPage;
                  //ViewState[CurrentPage.ToString()] = DGrid.Items[0].Cells[0].Text;

                  DataA.Fill(DataS2, CIndex, pageSize, "Waveplate");
                  DGrid.DataSource = DataS2;
                  DGrid.DataMember = "Waveplate";
                  DataView MiDView = DataS2.Tables["Waveplate"].DefaultView;
                  int Rcount = MiDView.Table.Rows.Count;
                  LabelC.Text = Rcount.ToString();
                  ViewState["CurrentPage"] = CurrentPage;
                  //ViewState[CurrentPage.ToString()] = DGrid.Items[0].Cells[0].Text;
                  //DGrid.CurrentPageIndex = DGrid.Page;
                  //DataS["Timestamp"] = DateTime.Now.Date.ToLocalTime();
                  //DTable.Clear();
                  //DTable.Columns.Clear();
                  int RCount = DataS2.Tables["Waveplate"].Rows.Count;
                  //LabelC.Text = RCount.ToString();
                  
                  DataS2.Tables.Add();
                  DGrid.DataBind();
                  //Session["Waveplate"]= DataS2;
                  //string LastRecord = DataS2.Tables["Waveplate"].Rows[Rcount -1]["Physical_Location"].ToString();
                  
                  DGrid.VirtualItemCount.ToString();
                  
                  //ViewState["LastKey"] = DGrid.DataKeys[DGrid.Items.Count];
                  //ViewState["FirstKey"] = DGrid.DataKeys[-1];
                  //int Physical_Location = Convert.ToInt32(ViewState["FirstKey"]);
                  //int Physical_Location = Convert.ToInt32(ViewState["LastKey"]);
            
                  //SqlDataAdapter DataA = new SqlDataAdapter("Select * from Waveplate", Conn);

                  //DataA.Fill(Dset,"Waveplate");
                  /*if (DGrid.Items.Count < DGrid.PageSize)
                  {
                        NEXT.Enabled = false;
                  
                  }

                  else
                  {
                        LAST.Enabled = false;

                  }*/

                  
                  Conn.Close();
            }                        
            
            
            }
            
            
      }







0
devlins
Asked:
devlins
  • 4
  • 3
1 Solution
 
mmarinovCommented:
Hi devlins,

the problem is that you don't set a datasource ( as far as i saw ) to the datagrid in
          public void DGrid_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
          {
               
               DGrid.CurrentPageIndex = e.NewPageIndex;
               
               //DGrid.DataSource = your_datasource;  
               DGrid.DataBind();
          }


Regards!
B..M
0
 
devlinsAuthor Commented:
The IListSource does not contain a data source name

The error above is what happens when I add DGrid.DataBind(); and the datasource..

Any suggestions?????
0
 
mmarinovCommented:
can you most the code that you have tried to execute - what datasource have you put on your_datasource ?

B..M
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
devlinsAuthor Commented:
I used DGrid.DataSource = DataS2; and DGrid.DataBind();

Is it better to used stored procedures for custom paging???

Thanks
0
 
mmarinovCommented:
the error means that DataS2 is null when you call DataBind method
debug the application and check it

B..M
0
 
devlinsAuthor Commented:
What I have done is bind the navigation to the function below and now I get an sql statement error, how should I set up the sql statement to read the data
what the paging process begins?????  

protected void Bind()

            {
            SqlConnection DConn =null;
                  SqlDataAdapter SDa = null;

                  int CIndex = 0;
                  int pageSize = 10;
                  
                  Conn.Open();
                        
                  //string LastRecord = DSet2.Tables["Waveplate"].Rows[pageSize -1]["Physical_Location"].ToString();
                  string sqlCo  = "SELECT Top"+pageSize+ "* From Waveplate ";
                  
                  DataA = new System.Data.SqlClient.SqlDataAdapter(sqlCo, Conn);
                        
                  DataTable DTable = new DataTable();
                  
                  //sqlC.CommandText = "Select * from Main_Wave_Inv, Conn"; //(Retardation, Retardation)(@Eq1,@Eq2)",Conn) ;
                  CIndex += pageSize;
                  
                  ViewState["CurrentPage"] = CurrentPage;
                  //ViewState[CurrentPage.ToString()] = DGrid.Items[0].Cells[0].Text;

                  DataA.Fill(DataS2, CIndex, pageSize, "Waveplate");
                  
                  DGrid.DataMember = "Waveplate";
                  DataView MiDView = DataS2.Tables["Waveplate"].DefaultView;
                  int Rcount = MiDView.Table.Rows.Count;
                  LabelC.Text = Rcount.ToString();
                  ViewState["CurrentPage"] = CurrentPage;
                  
                  int RCount = DataS2.Tables["Waveplate"].Rows.Count;
                  
                  DGrid.DataSource = DataS2;
                  DataS2.Tables.Add();
                  DGrid.DataBind();
                  
                  
                  DGrid.VirtualItemCount.ToString();
                  
                  
            
                  //SqlDataAdapter DataA = new SqlDataAdapter("Select * from Waveplate", Conn);

                  //DataA.Fill(Dset,"Waveplate");
                  /*if (DGrid.Items.Count < DGrid.PageSize)
                  {
                        NEXT.Enabled = false;
                  
                  }

                  else
                  {
                        LAST.Enabled = false;

                  }*/

                  
                  Conn.Close();
            }                        
            
             
0
 
mmarinovCommented:
you should use it like this ( example taken from MSDN )
SqlDataAdapter da = new SqlDataAdapter();
  SqlCommand cmd;

  // Create the SelectCommand.

  cmd = new SqlCommand("SELECT * FROM Customers " +
                       "WHERE Country = @Country AND City = @City", conn);

  cmd.Parameters.Add("@Country", SqlDbType.NVarChar, 15);
  cmd.Parameters.Add("@City", SqlDbType.NVarChar, 15);

  da.SelectCommand = cmd;

  // Create the InsertCommand.

  cmd = new SqlCommand("INSERT INTO Customers (CustomerID, CompanyName) " +
                       "VALUES (@CustomerID, @CompanyName)", conn);

  cmd.Parameters.Add("@CustomerID", SqlDbType.NChar, 5, "CustomerID");
  cmd.Parameters.Add("@CompanyName", SqlDbType.NVarChar, 40, "CompanyName");

  da.InsertCommand = cmd;

  return da;


B..M
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now