Link to home
Create AccountLog in
Avatar of Wizilling
WizillingFlag for New Zealand

asked on

how to repopulate a Gridveiw when using parameters

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.

ASKER CERTIFIED SOLUTION
Avatar of Anurag Agarwal
Anurag Agarwal
Flag of India image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
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 + "'");
        }
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.