0

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.

1

1 Answer 1

1

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();
 }
5
  • Thanks. I am getting Error 2 The type or namespace name 'Parameter' could not be found (are you missing a using directive or an assembly reference?)
    – Nate Pet
    Oct 22, 2012 at 19:43
  • Add using System.Web.UI.WebControls; in your usings.
    – Francis P
    Oct 22, 2012 at 19:46
  • Thanks Francis. I did that but it is still not working. Is there anything I am missing in the .aspx file that you can see?
    – Nate Pet
    Oct 22, 2012 at 19:50
  • Yes, I changed it to WtrClientDS.SelectParameters.Add(new Parameter("LocId", System.TypeCode.String, value)); , you had it as Int32 but as it is a string, I just changed to string
    – Nate Pet
    Oct 22, 2012 at 19:57
  • let us continue this discussion in chat
    – Nate Pet
    Oct 22, 2012 at 20:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.