?
Solved

how to repopulate a Gridveiw when using parameters

Posted on 2008-06-11
3
Medium Priority
?
263 Views
Last Modified: 2013-11-26
Hi,

in my asp.net project i have placed a text box, a button, and a gridview.
I will enter some text on the text box and click the button. The button should run the query " select * from table where value=something" and populate the grid view. I dont know how to do this.

Any examples or links to read on will be very helpful ?

i can get the grid to display All of the data.. but i want after the page loads, i insert my own filter and re-populate the grid...

I am using VB Studion 2005 standart, asp.net website project and vb language.

0
Comment
Question by:Wizilling
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
Anurag Agarwal earned 1200 total points
ID: 21766007
Currently you must be loading your grid in page load function.

Put this code in

If(NOT IsPostBack) Then
       LoadGrid('Default load condition')
End IF

Also make a function for the logic of populating the grid starting from making the query & database hit & setting the datasource of grid. Function should be like

Public Sub LoadGrid(ByVal whereCondition as String)
--
--
End Sub

Now call this function from page load when page loaded for first time with default where condition i.e. condition to load grid for first time.

On button click event call this function LoadGrid('textbox value') . this will repopulate the grid with your filter.

Let me know if you face any problem implementing this.

Anurag
0
 
LVL 5

Expert Comment

by:Qaiser_Mehmood_Mughal
ID: 21766568
this is the one way, create a method and pass the query based on ur requirment and the get the dataset and then bound this dataset to gridview again.    

    protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData("Select * from customers");
            }
        }

        private DataSet LoadData(string strQuery)
        {
            DataSet objDataSet=new DataSet();
            // Use the SQLCommand to fill the data set
            return objDataSet;
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            LoadData("Select * from customers where customerName='" + txtName + "'");
        }
0
 
LVL 5

Assisted Solution

by:Qaiser_Mehmood_Mughal
Qaiser_Mehmood_Mughal earned 800 total points
ID: 21766589
The Second option is to get the default view of your dataset object which is going to bound and then filter this object as many time as you want, based on the search criteria.

                DataSet objDataSet = new DataSet();
                DataView dv= objDataSet.Tables[0].DefaultView;
                // For DV, you can use following methods for seach.
                //dv.RowFilter
                //dv.Find();
                //dv.FindRows();
0

Featured Post

Certified OpenStack Administrator Course

We just refreshed our COA course based on the Newton exam.  With 14 labs, this course goes over the different OpenStack services that are part of the certification: Dashboard, Identity Service, Image Service, Networking, Compute, Object Storage, Block Storage, and Orchestration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question