Brian McCarthy
Brian McCarthy

Reputation: 4784

ASP.NET C# - Do you need seperate datasources for each gridview of different tables in same database?

Sorry, this is a bit of a noob question, but do you need a separate datasources for each gridview if each gridview is accessing the same database but different tables in the database?

For example: I have 3 different grid views dispaying searches for 1) given ZipCode and PlanCode, 2) given ZipCode, PlanCode, and Age, 3) given State Code and Carrier Code.

Here's the c# code-behind:

protected void Search_Zip_Plan_Age_Button_Click(object sender, EventArgs e)
{
    var _with1 = this.ZipPlan_SqlDataSource;
    _with1.SelectParameters.Clear();

    string ConnectionString = System.Configuration.ConfigurationManager.AppSettings["PriceFinderConnectionString"]
    _with1.SelectCommand = "ssp_get_zipcode_plan";
    _with1.SelectParameters.Add("ZipCode", this.ZipCode.Text);
    _with1.SelectParameters.Add("PlanCode", this.PlanCode.Text);
    _with1.SelectParameters.Add("Age", this.Age.Text);        

    _with1.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;

    _with1.CancelSelectOnNullParameter = false;


    Search_Results_GridView.DataBind();
}

thanks!

Upvotes: 2

Views: 934

Answers (1)

Brian Mains
Brian Mains

Reputation: 50728

You can reuse data source controls only if its the same query; otherwise, you need different data source controls.

HTH.

Upvotes: 1

Related Questions