Reputation: 46322
I have the following and it seems to work fine:
In my .cs file :
protected void menu_ItemClick(object sender, Telerik.Web.UI.RadMenuEventArgs e)
{
string value = (e.Item.Value).ToString();
WtrClientDS.SelectCommand = "SELECT * from Prog where ProgId = " + value;
}
In the .aspx file:
<asp:SqlDataSource ID="WtrClientDS" runat="server" ConnectionString="<%$ ConnectionStrings:ProgSQL %>">
</asp:SqlDataSource>
As mentioned, what I have above works fine but I do not think it is best practice.
What Like to do instead is something where I have the select command inside of the .aspx file like the following but not working:
Inside of the .cs file
protected void menu_ItemClick(object sender, Telerik.Web.UI.RadMenuEventArgs e)
{
string value = (e.Item.Value).ToString();
// changed below per input from user but still does not work.
WtrClientDS.SelectParameters.Add(new Parameter("LocId", System.TypeCode.String, value));
}
Inside of the .aspx file:
<asp:SqlDataSource ID="WtrClientDS" runat="server" ConnectionString="<%$ ConnectionStrings:ProgSQL %>"
SelectCommand = "SELECT * from Prog where ProgId = @LocId">
<SelectParameters>
<asp:Parameter Name="LocId" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
What I have above simply does not work. Doesn't give an error but simply does not work. I also wanted to know which is the more preferred method/ideal way of doing it.
Upvotes: 0
Views: 162
Reputation: 13665
Try using a new SQLDataSource
:
protected void menu_ItemClick(object sender, Telerik.Web.UI.RadMenuEventArgs e)
{
string value = (e.Item.Value).ToString();
string strConn = ConfigurationManager.ConnectionStrings["ConnectionStrings:ProgSQL"].ConnectionString;
SqlDataSource WtrClientDS = new SqlDataSource();
WtrClientDS.ConnectionString = strConn;
WtrClientDS.SelectCommand = "SELECT * from Prog where ProgId = @LocId"
WtrClientDS.SelectParameters.Add(new Parameter("LocId", System.TypeCode.String, value));
//refresh your control
WtrClients.DataSource = WtrClientDS.Select(DataSourceSelectArguments.Empty);
WtrClients.Rebind();
}
Upvotes: 1