Solved

how to repopulate a Gridveiw when using parameters

Posted on 2008-06-11
3
250 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:
Anurag Agarwal 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
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…

827 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