Search in Grid

May 2, 2012 at 6:36 AM

Hi Is there anything inbuilt for searching in Grid.

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Admin_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <ext:PageManager ID="PageManager1" runat="server" />
    <div>
        
    </div>
    <div>
        <ext:Grid Title="List Of Registered Students" runat="server" ID="gvStudents" Width="800px"
            PageSize="5" ShowBorder="true" ShowHeader="true" AutoHeight="true" EnableCheckBoxSelect="True"
            DataKeyNames="StudId" EnableRowNumber="True">
            <Columns>
                <ext:BoundField DataField="StudId" HeaderText="StudId" Width="30" Hidden="true" runat="server" />
                <ext:BoundField DataField="Name" HeaderText="Name" Width="180" runat="server" DataToolTipField="Name" />
                <ext:BoundField DataField="Area" HeaderText="Area" Width="120" runat="server" />
                <ext:BoundField DataField="Mobile" HeaderText="Contact" Width="80" runat="server" />
                <ext:BoundField DataField="ParrentOfficeTelNo" HeaderText="Parent Contact" Width="80"
                    runat="server" />
                <ext:BoundField DataField="AdmissionDate" HeaderText="Adm. Date" Width="110" runat="server" />
                <ext:BoundField DataField="STDName" HeaderText="Adm. Std" Width="100" runat="server" />
            </Columns>
            <Toolbars>
                <ext:Toolbar>
                    <Items>
                        <ext:TextBox ID="txtSearch" runat="server" Label="Label" Text="" EmptyText="Search by Student Name"
                            Width="200px">
                        </ext:TextBox>
                        <ext:Button ID="Button1" runat="server" Text="Search" OnClick="Button1_Click" EnablePostBack="true"></ext:Button>
                    </Items>
                </ext:Toolbar>
            </Toolbars>
        </ext:Grid>
    </div>
    <div>
    
    </div>
    </form>
</body>
</html>

Code Behind 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Admin_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            bindStudentGrid();
        }

    }

    private void bindStudentGrid()
    {

        NewUser nu = new NewUser();
        nu.StudId = 0;
        DataSet dsStud = nu.getStudent(nu);
        if (dsStud.Tables[0].Rows.Count > 0)
        {
            gvStudents.DataSource = dsStud;
            gvStudents.DataBind();


        }
        //lblmsg.Text = "List Of Student";
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        txtSearch.Text = "Hi";
        NewUser nu = new NewUser();

        nu.FirstName = txtSearch.Text;

        DataSet dsStud = nu.getSearchStudent(nu);
        if (dsStud.Tables[0].Rows.Count > 0)
        {

            gvStudents.DataSource = dsStud;
            gvStudents.DataBind(); //Object reference not set to an instance of an object.


        }

    }
    
}

 

May 2, 2012 at 8:02 AM

Solved.

 

Thanks