M
Morris Neuman
Hi,
My website can use either an SQL or Access database, based on the setting in
the web.config file.
<appSettings>
<!--If using Access then set value="AccessDataSource1"/>-->
<!--If using MS SQL then set value="SqlDataSource1"/>-->
<add key="MyDataSource" value="SqlDataSource1"/>
</appSettings>
In my content page I have
1) a gridview defined as follows:
<asp:GridView ID="GridView1" runat="server"
AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" DataKeyNames="AttendantID,TimeOfDay"
DataSourceID='<%$ AppSettings:MyDataSource %>' >
<Columns>
< columns defined>
</Columns>
2) a button and textbox defined as:
<asp:Button id="Button2" runat="server" Text="View Selected"
onclick="Button2_Click" />
<br />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
3) I have also defined a Button2_Click event as follows:
protected void Button2_Click(object sender, EventArgs e)
{
SqlDataSource1.SelectCommand = "SELECT Attendant.AttendantID,
Attendant.TimeOfDay, AttTimeOfDayXref.TimeOfDayNumber,
AttTimeOfDayXref.TimeOfDayDescription, Attendant.ExtensionToDial,
Attendant.DirectoryListing FROM Attendant INNER JOIN AttTimeOfDayXref ON
Attendant.TimeOfDay = AttTimeOfDayXref.TimeOfDayNumber WHERE AttendantID = "
+ TextBox2.Text;
GridView1.DataBind();
}
My question is how can I set the Button2_Click event to allow the
SqlDataSource1.SelectCommand to reflect the chosen database based on the app
setting in web.config.
I tried
<%$ AppSettings:MyDataSource %>.SelectCommand, using different syntax and
keep getting and error.
Can you tell me the code to use in the Button2_Click event so I can
reference the app setting from the web.config in the .SelectCommand?
My website can use either an SQL or Access database, based on the setting in
the web.config file.
<appSettings>
<!--If using Access then set value="AccessDataSource1"/>-->
<!--If using MS SQL then set value="SqlDataSource1"/>-->
<add key="MyDataSource" value="SqlDataSource1"/>
</appSettings>
In my content page I have
1) a gridview defined as follows:
<asp:GridView ID="GridView1" runat="server"
AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" DataKeyNames="AttendantID,TimeOfDay"
DataSourceID='<%$ AppSettings:MyDataSource %>' >
<Columns>
< columns defined>
</Columns>
2) a button and textbox defined as:
<asp:Button id="Button2" runat="server" Text="View Selected"
onclick="Button2_Click" />
<br />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
3) I have also defined a Button2_Click event as follows:
protected void Button2_Click(object sender, EventArgs e)
{
SqlDataSource1.SelectCommand = "SELECT Attendant.AttendantID,
Attendant.TimeOfDay, AttTimeOfDayXref.TimeOfDayNumber,
AttTimeOfDayXref.TimeOfDayDescription, Attendant.ExtensionToDial,
Attendant.DirectoryListing FROM Attendant INNER JOIN AttTimeOfDayXref ON
Attendant.TimeOfDay = AttTimeOfDayXref.TimeOfDayNumber WHERE AttendantID = "
+ TextBox2.Text;
GridView1.DataBind();
}
My question is how can I set the Button2_Click event to allow the
SqlDataSource1.SelectCommand to reflect the chosen database based on the app
setting in web.config.
I tried
<%$ AppSettings:MyDataSource %>.SelectCommand, using different syntax and
keep getting and error.
Can you tell me the code to use in the Button2_Click event so I can
reference the app setting from the web.config in the .SelectCommand?