Aubergine
Aubergine

Reputation: 6042

ConnectionString changes when adding second GridView

I am forced to use .NET WebForms wizards for MSc labs. I cannot describe my feelings after Spring on Java, I SUFFER.

When configuring data-source for a GridView I noticed that ConnectionString overwrites itself when you add the second GridView2 and choose the same dataSource as for GridView1 to the server form while changing the SQL to display data from the other table. As a result it makes GridView1 to query the same data as second GridView2..

How does this work? In java dataSource is not bound to any ConnectionString/SQL statement... - we can use it with as many different sql queries as we want , why here it is an issue?

Thanks,

Upvotes: 0

Views: 68

Answers (1)

Alex
Alex

Reputation: 841

SqlDataSource contains select string in its SelectCommand property and connection string in the ConnectionString property. So you have to create another datasource for the second GridView or change its properties dynamically in C#.

if(dataBoundFirstGridView)
{
    SqlDataSource1.ConnectionString = "..";
    SqlDataSource1.SelectCommand = "select * from table1";
}

Upvotes: 1

Related Questions