Solved

how to repopulate a Gridveiw when using parameters

Posted on 2008-06-11
3
245 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
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
anuragal earned 300 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 200 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

809 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