Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
Html File
 

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="user_info.aspx.cs" Inherits="jQueryUploadTest.user_info" %>
 
<!DOCTYPE html>
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
 
     <link href="css/img/StyleSheet.css" rel="stylesheet" />
    <script src="js/jquery-1.4.1.min.js"></script>
    <script src="js/jquery.dynDateTime.min.js"></script>
    <script src="js/calendar-en.min.js"></script>
    <link href="css/calendar-blue.css" rel="stylesheet" />
 

    <title>Uploaded Files</title>
      <script type="text/javascript">
          jQuery(document).ready(function () {
              jQuery("#createdOn").dynDateTime({
                  showsTime: true,
                  ifFormat: "%d/%m/%Y ",
                  daFormat: " %p,  %m,  %Y",
                  align: "TL",
                  electric: false,
                  singleClick: false,
                  displayArea: ".siblings('.dtcDisplayArea')",
                  button: ".next()" //next sibling
              });
          });
  </script>
 

 
     <style type="text/css">
         .auto-style1 {
             width: 100%;
         }
         .auto-style2 {
             width: 147px;
             height: 61px;
         }
         .auto-style3 {
             width: 124px;
             height: 61px;
         }
         .auto-style5 {
             width: 147px;
             height: 24px;
         }
         .auto-style6 {
             width: 124px;
             height: 24px;
         }
         .auto-style8 {
             height: 24px;
             width: 518px;
         }
         .auto-style9 {
             width: 175px;
             height: 24px;
         }
         .auto-style10 {
             width: 175px;
             height: 61px;
         }
         .auto-style11 {
             height: 61px;
             width: 518px;
         }
     </style>
 
    </head>
<body>
   <form runat="server" style="width: 569px">
 

       <table class="auto-style1">
           <tr>
               <td class="auto-style5">FileName</td>
               <td class="auto-style6">FileInformation</td>
               <td class="auto-style9">CreatedOn</td>
               <td class="auto-style8">StatusName</td>
           </tr>
           <tr>
               <td class="auto-style2">
                   <asp:TextBox ID="fileName" runat="server" AutoPostBack="true" Width="100px" Font-Size="11px" OnTextChanged="getId" ></asp:TextBox>
               </td>
               <td class="auto-style3">
                   <asp:TextBox ID="fileType" runat="server" AutoPostBack="true" Width="100px" Font-Size="11px" OnTextChanged="getId" ></asp:TextBox>
               </td>
               <td class="auto-style10">
                    <asp:TextBox  ID="createdOn" runat="server" AutoPostBack="true" Width="100px" Font-Size="11px"  Height="16px" OnTextChanged="createdOn_TextChanged"></asp:TextBox>
 
                        <button id="datePick" type="button" style="height: 43px; width: 38px;background-image:url(image\calendar.png)" ></button>
 

               </td>
               <td class="auto-style11">
                    <asp:DropDownList ID="ddlstatusName"   runat="server" AutoPostBack="True" Width="100px" Font-Size="11px" OnSelectedIndexChanged="ddlstatusName_SelectedIndexChanged">
                        <asp:ListItem>completed</asp:ListItem>
                        <asp:ListItem>success</asp:ListItem>
                        <asp:ListItem>pending</asp:ListItem>
                        <asp:ListItem>progressing</asp:ListItem>
                        <asp:ListItem>yet to start</asp:ListItem>
                        <asp:ListItem>failure</asp:ListItem>
                   </asp:DropDownList>
               </td>
           </tr>
       </table>
       <br />
       <br />
       <asp:GridView ID="GridView1" runat="server" AllowPaging="True" EnableSortingAndPagingCallbacks="True" OnRowDataBound="GridView1_RowDataBound1">
       </asp:GridView>
 
       <br />
  </form>
</body>
</html>
 
code Behind File
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Net.Mail;
using System.Drawing;
namespace jQueryUploadTest
{
    public partial class user_info : System.Web.UI.Page
    {
        int i = 0;
        SqlDataAdapter da;
        DataTable table;
        DataSet ds = new DataSet();
        SqlConnection Connection = new SqlConnection("Data Source=.;Initial Catalog=printapp_apr_2;Integrated Security=True");
        string keyid;
        string statusId;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BindData();
            }
        }
        private void BindData()
        {
            try
            {
                string key = Session["email"].ToString();
                string query = "select f.fileName,(f.fileType + Char(13) + f.fileSize)as fileInfo,f.createdOn,f.statusId,s.statusName from fileInfo As f left join status As s on f.statusId=s.statusId where userId=(select userId from userInfo where email ='" + key + "')";
                da = new SqlDataAdapter(query, Connection);
                table = new DataTable();
 
                GridView1.DataSource = table; //This should be replaced with your datasource
                GridView1.EnableViewState = true;
                GridView1.AllowPaging = true;
                GridView1.PageSize = 4;
                GridView1.DataBind();
                GridView1.EnableSortingAndPagingCallbacks = true;
                da.Fill(table);
                //GridView1.DataSource = table;
                GridView1.DataBind();
            }
            catch(Exception ex)
            {
            }
          
 
        }
 

        public void getId(object sender, EventArgs e)
        {
            string FormatOption = ((TextBox)sender).ID;
            string FormatText = ((TextBox)sender).Text;
            Connection.Open();
            string qury = "select  f.fileName,(f.fileType + '' + f.fileSize)as fileInfo,f.createdOn,f.statusId,s.statusName from fileInfo As f left join status As s on f.statusId=s.statusId where  " + FormatOption + "  like '" + FormatText + "%" + "'";
            SqlCommand cmd = new SqlCommand(qury, Connection);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            GridView1.DataSource = ds;
            GridView1.DataBind();
 
        }
        protected void info_Sorting(object sender, GridViewSortEventArgs e)
        {
            switch (e.SortExpression)
            {
                case "Melder":
                    if (e.SortDirection == SortDirection.Ascending)
                    {
                        // GridView1.DataSource = ; // Asc query for Melder field;
                        GridView1.DataBind();
                    }
                    else
                    {
                        // GridView1.DataSource =; // Desc query for Melder field ;
                        GridView1.DataBind();
                    }
 
                    break;
 
                // case statements for your other fields.
            }
        }
     
 
        protected void GridView1_RowDataBound1(object sender, GridViewRowEventArgs e)
        {
            try
            {
                if (i > 0 && e.Row.Cells[3].Text != "&nbsp;")
                {
                    Connection.Open();
                    SqlCommand Command1 = Connection.CreateCommand();
                    Command1.CommandText = "select statusColor, statusName from status where statusId=" + e.Row.Cells[3].Text;
                    SqlDataReader reader = Command1.ExecuteReader();
                    while (reader.Read())
                    {
                        e.Row.BackColor = System.Drawing.ColorTranslator.FromHtml(reader[0].ToString());
                    }
 

                }
 
                i++;
                e.Row.Cells[3].Visible = false;
                Connection.Close();
            }
            catch (Exception ex)
            {
            }
        }
 
        protected void ddlstatusName_SelectedIndexChanged(object sender, EventArgs e)
        {
            string statusName = ddlstatusName.SelectedItem.Text;
            string query = "select  f.fileName,(f.fileType + '' + f.fileSize)as fileInfo,f.createdOn,f.statusId,s.statusName from fileInfo As f left join status As s on f.statusId=s.statusId where  statusName = '" + statusName + "'";
            SqlCommand comd = new SqlCommand(query, Connection);
            SqlDataAdapter da1 = new SqlDataAdapter(comd);
            DataSet ds1 = new DataSet();
            da1.Fill(ds1);
            GridView1.DataSource = ds1;
            GridView1.DataBind();
        }
 
        protected void createdOn_TextChanged(object sender, EventArgs e)
        {
            Connection.Open();
            string s = createdOn.Text;
 
            BindData();
            DataView rd = new DataView(table);
            string SearchRegdate = null;
            if (!String.IsNullOrEmpty(s))
            {
                SearchRegdate = string.Format("{0} '%{1}%'", GridView1.SortExpression, s);
 
            }
            rd.RowFilter = "Convert(createdOn,System.String) like " + SearchRegdate;
            da.Fill(ds);
            GridView1.DataSource = rd;
            GridView1.DataBind();
            Connection.Close();
 
            //Connection.Open();
            //string s = createdOn.Text;
            ////string s1 = s.Remove(s.Length - 12);
            ////Label1.Text = s;
            //BindData();
            //DataView rd = new DataView(table);
            //string SearchRegdate = null;
            //if (!String.IsNullOrEmpty(s))
            //{
            //    SearchRegdate = string.Format("{0} '%{1}%'", GridView1.SortExpression, s);

            //}
            //rd.RowFilter = "Convert(createdOn,System.String) like " + SearchRegdate;
            //da.Fill(ds);
            //GridView1.DataSource = rd;
            //GridView1.DataBind();
        }
 
        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndexChanging += new GridViewPageEventHandler(GridView1_PageIndexChanging);
            //GridView1.PageIndex = e.NewPageIndex;
            //GridView1.DataBind();
        }
       
   
    }
}
 
it cannot able to dispaly in the second page in gridview...
Posted 9-Apr-13 2:43am
Rekhash1.5K
Edited 9-Apr-13 2:46am
RyanDev129.8K
v3
Comments
ryanb31 at 9-Apr-13 7:45am
   
Can you narrow down where your issue is and be more specific?
Rekhash at 9-Apr-13 7:49am
   
@ryanb31
in gridview in 1,2,3.. if i click page 2 .. it cannot display page...
Anil Honey 206 at 9-Apr-13 7:56am
   
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{

GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
}
 
have u try this one
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Replace these two functions with the following updated functions:
private void BindData()
{
    try
    {
        string key = Session["email"].ToString();
        string query = "select f.fileName,(f.fileType + Char(13) + f.fileSize)as fileInfo,f.createdOn,f.statusId,s.statusName from fileInfo As f left join status As s on f.statusId=s.statusId where userId=(select userId from userInfo where email ='" + key + "')";
        da = new SqlDataAdapter(query, Connection);
        table = new DataTable();
        GridView1.EnableViewState = true;
        GridView1.AllowPaging = true;
        GridView1.PageSize = 4;
        GridView1.DataBind();
        GridView1.EnableSortingAndPagingCallbacks = true;
        da.Fill(table);
        GridView1.DataSource = table;
        GridView1.DataBind();
        Session["table"] = table; //Store data in session for paging.
        GridView1.PageIndexChanging += new GridViewPageEventHandler(GridView1_PageIndexChanging);
    }
    catch(Exception ex)
    {
    }
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    if(Session["table"]!=null){
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.DataSource = Session["table"];
        GridView1.DataBind();
    }
}
 

--Amit
  Permalink  
v2
Comments
Rekhash at 9-Apr-13 8:01am
   
@_Amy
if(Session["table"]!=-null) -- this operator can not be operand.. it showing error in page...
_Amy at 9-Apr-13 8:04am
   
Oh! Typing mistake. Remove "-". :) Check my updated solution.
Rekhash at 9-Apr-13 8:18am
   
@_Amy
in gridview in 1,2,3.. if i click page 2 .. it cannot display page...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Use This
 
I Used Datasource=table coz you take all data in dable in BindData()
 
protected void GridView1_PageIndexChanging(object sender, System.Web.UI.WebControls.GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataSource = table;
GridView1.DataBind();
 

}
  Permalink  
v2
Comments
Rekhash at 9-Apr-13 8:31am
   
@TusharKhairnar
i am doing in asp.net using c#

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 5,170
1 DamithSL 4,357
2 Maciej Los 3,750
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,851


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 9 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100