in FormView Pager Template shown in design page but not shown in runtime.....

////////////////////////////////////////////////////

//////////////////////MY TABLE//////////////////

////////////////////////////////////////////////////


USE [logistics_tab]
GO

/****** Object:  Table [dbo].[dtype]    Script Date: 02/07/2015 10:19:00 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[dtype](

[dtid] [int] IDENTITY(1,1) NOT NULL,
[dtcd] [char](5) NOT NULL,
[desp] [char](15) NOT NULL,
 CONSTRAINT [PK_dtype] PRIMARY KEY CLUSTERED 
(
[dtid] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY],

 CONSTRAINT [Uq_dtcd_Dtype] UNIQUE NONCLUSTERED 
(
[dtcd] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO


////////////////////////////////////////////////////
////////////MY STORED PROCEDURE/////////////////////
////////////////////////////////////////////////////
USE [logistics_tab]
GO

/****** Object:  StoredProcedure [dbo].[dtype_pro]    Script Date: 02/07/2015 10:21:42 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[dtype_pro]
(
@dtid as int=0,
@dtcd as char(5)='',
@desp as char(15)='',
@status as varchar(50)=''
)
AS
BEGIN
SET NOCOUNT ON;
if(@status = 'Display')
begin
Select * from dtype
end
else if(@status = 'Add')
begin
Insert into dtype(dtcd,desp) values (@dtcd,@desp)
end
else if(@status = 'Update')
begin
Update dtype set dtcd=@dtcd, desp=@desp where dtid=@dtid
end
else if(@status = 'Delete')
begin
Delete from dtype where dtid=@dtid
end
END
GO

////////////////////////////////////////////////////

//////////MY DESIGN PAGE/////////////

////////////////////////////////////////////////////

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="DestnType.aspx.cs" Inherits="LogisticsApp.DestnType" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<asp:FormView ID="FormView1" runat="server" DataKeyNames= "dtid" GridLines="Both" 
        AllowPaging="True" PagerStyle-BorderStyle="NotSet" PagerStyle-ForeColor="Black">

        <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
        <PagerStyle BackColor="#B5C7DE" ForeColor="Black" HorizontalAlign="Center" Font-Bold="true" Font-Size="Large"/>
        <ItemTemplate>
                  <table>
                    <tr><td align="right"><b>Employee ID:</b></td><td><%# Eval("dtid") %></td></tr>
                    <tr>
                      <td colspan="2">
                        <asp:LinkButton ID="EditButton"
                                        Text="Edit"
                                        CommandName="Edit"
                                        RunAt="server"/>
                          &nbsp;
                        <asp:LinkButton ID="NewButton"
                                        Text="New"
                                        CommandName="New"
                                        RunAt="server"/>
                          &nbsp;
                        <asp:LinkButton ID="DeleteButton"
                                        Text="Delete"
                                        CommandName="Delete"
                                        RunAt="server"/>
                      </td>
                    </tr>
                  </table>                 
                </ItemTemplate>

                <PagerTemplate>
                <table>
                    <tr>
                      <td><asp:Button ID="FirstButton1" CommandName="Page" CommandArgument="First" 
                      Text="<1<" RunAt="server" Font-Bold="True" />&nbsp;</td>
                      </tr>
                  </table>
                </PagerTemplate>
</asp:FormView>
</asp:Content>

/////////////////////////////////
 ///////MY CODE///////////

////////////////////////////

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Text.RegularExpressions;
    namespace LogisticsApp
    {
        public partial class DestnType : System.Web.UI.Page
        {
            public LogisticsApp.MyConnection.OfcConn constr = new MyConnection.OfcConn();
            SqlConnection con;
            SqlCommand com;
            SqlDataAdapter sqlda;
            DataSet ds;
            DataTable dt;//for form view
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    BindGrid();
                }
            }
            protected void BindGrid()
            {
                try
                {
                    con = new SqlConnection(constr.str);
                    dt = new DataTable();//for form view
                    com = new SqlCommand();
                    con.Open();
                    com.Connection = con;
                    com.CommandText = "dtype_pro";
                    com.CommandType = CommandType.StoredProcedure;
                    com.Parameters.Add(new SqlParameter("@status",             SqlDbType.VarChar, 50));
                    com.Parameters["@status"].Value = "Display";
                    sqlda = new SqlDataAdapter(com);
                    ds = new DataSet();
                    sqlda.Fill(dt);//for formview
                    sqlda.Fill(ds);
                    if (ds.Tables[0].Rows.Count > 0) //Check if DataTable returns data
                    {
                        FormView1.DataSource = dt;
                        DataBind();                
                    }
                }
                catch (Exception ex)
                {
                    //lblerr.Text = ex.Message;
                    throw ex;
                }
                finally
                {
                        if (con != null)
                         {
                                if (con.State == ConnectionState.Open)
                                con.Close();
                                con = null;
                         }
                  }
             }
                protected void DtypeFormView_PageIndexChanging(object sender, FormViewPageEventArgs e)
                {
                    FormView1.PageIndex = e.NewPageIndex;
                    BindGrid();
                }
            }
         }


//plz plz... help as soon as possible this is simple code but not show at run time....... :(

                    
February 7th, 2015 1:08am

Good day uzma abidi

It has been long time since I used Webforms but it look to me like you are using the default options and if there is no data that return in the query then you will not see the PagerTemplate.

1. execute the SP from the SSMS.

2. make sure that you pass the correct @status while executing the SP from the ASPX.

3. check the SQL Server profiler, what query the SQL Server got.

4. Check if DataTable (dt) has data after filling it. else you do not get the "DataBind" part, and the PagerTemplate will not display.

* The basic code look ok in fast review. I might missed something. You should monitor it and get the line that make the issue.

Free Windows Admin Tool Kit Click here and download it now
February 7th, 2015 5:06am

Hi uzma,

As the issue is more related to ASP.NET, I would like to recommend you post the question in the ASP.NET forums at http://forums.asp.net/ . I t is appropriate and more experts will assist you.

Thanks,
Lydia Zhang

February 9th, 2015 12:58am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics