Solved

how to repopulate a Gridveiw when using parameters

Posted on 2008-06-11
3
240 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now