0

我有以下内容,它似乎工作正常:

在我的 .cs 文件中:

 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;
 }

在 .aspx 文件中:

<asp:SqlDataSource ID="WtrClientDS" runat="server" ConnectionString="<%$ ConnectionStrings:ProgSQL %>">

</asp:SqlDataSource>

如前所述,我上面的工作正常,但我认为这不是最佳实践。

喜欢做的事情是我在 .aspx 文件中有 select 命令,如下所示,但不起作用:

.cs 文件内部

     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)); 
     }

.aspx 文件内部:

      <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>

我上面的内容根本行不通。不会给出错误,但根本不起作用。我还想知道哪种方法更受欢迎/更理想。

4

1 回答 1

1

尝试使用新的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();
 }
于 2012-10-22T19:41:30.383 回答