I have a connection string in my web.config and a gridview. below is code for how I configured my gridview.
<asp:GridView ID="GridView1" OnRowDataBound="GridView1_RowDataBound"
....
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:sb_cpdConnectionString %>"
SelectCommand="SELECT colID, lname, fname, address, hobby from table1 where column like '%' ">
<SelectParameters>
<asp:ControlParameter ControlID="TextBox1" Name="lname" PropertyName="Text"
Type="String" />
<asp:ControlParameter ControlID="TextBox1" Name="fname" PropertyName="Text"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
Since I want to show another gridview from my child data source and I am now using code behind, how do I bind my SqlDataSource to my databasae as I did in my aspx code.
Below is how I have done so far.
private SqlDataSource ChildDataSource(string strCustometId, string strSort)
{
string strQRY = "";
SqlDataSource ds = new SqlDataSource();
string connectionString = WebConfigurationManager.ConnectionStrings["sb_cpdConnectionString"].ConnectionString;
SqlConnection myConnection = new SqlConnection(connectionString);
myConnection.Open();
strQRY = "SELECT [ID], [QuizNo]," +
"[Status],[CertificateNo],[Received] FROM [cpd_certificates]" +
" WHERE [ID] = '" + strCustometId + "'" +
"HAVING COUNT(*)=0 " + strSort;
// this is where I need help to bind connection string.
I get an error: The connectionString property has been initialized.