This is a migrated thread and some comments may be shown as answers.

Paging problem

1 Answer 45 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Cristian
Top achievements
Rank 1
Cristian asked on 02 Sep 2011, 06:44 PM
Hi guys, i have 4 textboxes and a search button. When the search button is pressed a radgrid is binded depending on the value of the textboxes, the radgrid has enable paging=true,  after hitting the search button the textboxes are cleared the when I try to change page,the grid is not binded because there's no value in the textboxes, My question is if is it posible that after clear the textboxes and change the page of the radgrid keep the last value of the textboxes?

Here's my code to bind the grid
private void BuscaSolicitanteGrid()
     {
         try
         {
             if (rdTxtExp.Value != null)
             {
                 var bdInstContext = new BD_INSTEntities();
                 var empleados = from emp in bdInstContext.Empleados
                                 where emp.exp_emp == rdTxtExp.Value && emp.ind_edo_emp=="A"
                                 select emp;
                   
                 rgSolic.DataSource = empleados;
                 rgSolic.Rebind();
                 rgSolic.Visible = true;
                 rdTxtNom.Text = "";
                 rdTxtApat.Text = "";
                 rdTxtAmat.Text = "";
                
                 rdTxtExp.Value = null;
          
             }
             if (rdTxtNom.Text != "")
             {
                 var bdInstContextApat = new BD_INSTEntities();
                 var empleadoNombre = from emp in bdInstContextApat.Empleados
                                      where emp.nombre_emp == rdTxtNom.Text && emp.ind_edo_emp == "A"
                                      select emp;
                   
                 rgSolic.DataSource = empleadoNombre;
                 rgSolic.Rebind();
                 rgSolic.Visible = true;
                 rdTxtNom.Text = "";
                 rdTxtApat.Text = "";
                 rdTxtAmat.Text = "";
                 rdTxtExp.Value = null;
             
             }
             if (rdTxtApat.Text != "")
             {
                 var bdInstContextApat = new BD_INSTEntities();
                   
                 var empleadoApat = from emp in bdInstContextApat.Empleados
                                    where emp.paterno_emp == rdTxtApat.Text && emp.ind_edo_emp == "A"
                                    select emp;
                 rgSolic.DataSource = empleadoApat;
                 rgSolic.Rebind();
                 rgSolic.Visible = true;
                 rdTxtNom.Text = "";
                 rdTxtApat.Text = "";
                 rdTxtAmat.Text = "";
                 rdTxtExp.Value = null;
           
             }
             if (rdTxtAmat.Text != "")
             {
                 var bdInstContextAmat = new BD_INSTEntities();
                 var empleadosAmat = from emp in bdInstContextAmat.Empleados
                                     where emp.materno_emp == rdTxtAmat.Text && emp.ind_edo_emp == "A"
                                     select emp;
                 rgSolic.DataSource = empleadosAmat;
                 rgSolic.Rebind();
                 rgSolic.Visible = true;
                 rdTxtNom.Text = "";
                 rdTxtApat.Text = "";
                 rdTxtAmat.Text = "";
                 rdTxtExp.Value = null;
          
             }
             if (rdTxtNom.Text != "" && rdTxtApat.Text!="")
             {
                 var bdInstContextNom = new BD_INSTEntities();
                 var empleadoNom = from emp in bdInstContextNom.Empleados
                                   where emp.nombre_emp == rdTxtNom.Text && emp.paterno_emp == rdTxtApat.Text && emp.ind_edo_emp == "A"
                                 select emp;
                 rgSolic.DataSource = empleadoNom;
                 rgSolic.Rebind();
                 rgSolic.Visible = true;
                 rdTxtNom.Text = "";
                 rdTxtApat.Text = "";
                 rdTxtAmat.Text = "";
                 rdTxtExp.Value = null;
           
             }
             if (rdTxtNom.Text != "" && rdTxtAmat.Text != "")
             {
                 var bdInstContextNom = new BD_INSTEntities();
                 var empleadoNom = from emp in bdInstContextNom.Empleados
                                   where emp.nombre_emp == rdTxtNom.Text && emp.materno_emp == rdTxtAmat.Text && emp.ind_edo_emp == "A"
                                   select emp;
                 rgSolic.DataSource = empleadoNom;
                 rgSolic.Rebind();
                 rgSolic.Visible = true;
                 rdTxtNom.Text = "";
                 rdTxtApat.Text = "";
                 rdTxtAmat.Text = "";
                 rdTxtExp.Value = null;
              
             }
             if (rdTxtApat.Text!="" && rdTxtAmat.Text!="")
             {
                 var bdInstContextNom = new BD_INSTEntities();
                 var empleadoApellidos = from emp in bdInstContextNom.Empleados
                                         where emp.paterno_emp == rdTxtApat.Text && emp.materno_emp == rdTxtAmat.Text && emp.ind_edo_emp == "A"
                                   select emp;
                 rgSolic.DataSource = empleadoApellidos;
                 rgSolic.Rebind();
                 rgSolic.Visible = true;
                 rdTxtNom.Text = "";
                 rdTxtApat.Text = "";
                 rdTxtAmat.Text = "";
                 rdTxtExp.Value = null;
             
             }
             if (rdTxtNom.Text != "" && rdTxtApat.Text != "" && rdTxtAmat.Text != "")
             {
                 var bdInstContextNom = new BD_INSTEntities();
                 var empleadoApellidos = from emp in bdInstContextNom.Empleados
                                         where
                                             emp.nombre_emp == rdTxtNom.Text && emp.paterno_emp == rdTxtApat.Text &&
                                             emp.materno_emp == rdTxtAmat.Text && emp.ind_edo_emp == "A"
                                         select emp;
                 rgSolic.DataSource = empleadoApellidos;
                 rgSolic.Rebind();
                 rgSolic.Visible = true;
                 rdTxtNom.Text = "";
                 rdTxtApat.Text = "";
                 rdTxtAmat.Text = "";
                 rdTxtExp.Value = null;
                
             }
            
         }
         catch (Exception ex)
         {
             Alerta(ex.Message);
         }
          
         
     }
In page index change method I call again this method

Hope you could help me
 

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 02 Sep 2011, 08:22 PM
Hello,

please check below code snippet.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm8.aspx.cs" Inherits="TelerikTest.Web.WebForm8" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        </telerik:RadScriptManager>
       
        <br />
        <telerik:RadTextBox ID="RadTextBox1" runat="server">
        </telerik:RadTextBox>
        <telerik:RadButton ID="RadButton1" runat="server" Text="Search"
            onclick="RadButton1_Click">
        </telerik:RadButton>
        <br />
        <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource" Visible="false" AllowPaging="true" PageSize="1">
            <MasterTableView>
                <Columns>
                    <telerik:GridBoundColumn HeaderText="MyProperty" DataField="MyProperty" UniqueName="MyProperty">
                    </telerik:GridBoundColumn>
                    
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>
    </div>
    </form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
 
namespace TelerikTest.Web
{
    public partial class WebForm8 : System.Web.UI.Page
    {
 
 
        protected void Page_Load(object sender, EventArgs e)
        {
 
        }
        protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            if (!string.IsNullOrEmpty(RadTextBox1.Text.Trim()))
            {
                List<TempList> lstTempList = GetRecords();
                lstTempList = (from o in lstTempList
                               where o.MyProperty.ToLower().Contains(RadTextBox1.Text.Trim().ToLower())
                               select o).ToList();
                RadGrid1.Visible = true;
                RadGrid1.DataSource = lstTempList;
                RadTextBox1.Text = string.Empty;
            }
        }
 
        protected void RadButton1_Click(object sender, EventArgs e)
        {
            RadGrid1.Rebind();
        }
        protected List<TempList> GetRecords()
        {
            List<TempList> lstTempList = new List<TempList>();
            TempList obj1 = new TempList();
            TempList obj2 = new TempList();
            TempList obj3 = new TempList();
            TempList obj4 = new TempList();
 
            obj1.MyProperty = "ABC";
            lstTempList.Add(obj1);
 
            obj2.MyProperty = "AAA";
            lstTempList.Add(obj2);
 
            obj3.MyProperty = "BBB";
            lstTempList.Add(obj3);
 
            obj4.MyProperty = "CCC";
            lstTempList.Add(obj4);
 
            return lstTempList;
        }
    }
 
    public class TempList
    {
        public string MyProperty { get; set; }
    }
}

Let me know if any concern.

Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Cristian
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or