c# – 如何在SqlDataSource中传递属性值selectCommand where conditon?

我的page2.aspx.cs页面中有一个属性

public int? Id
{
        get
        {
            if (ViewState[Page1.Id] != null)
                return Convert.ToInt32(ViewState[Page1.Id]);
            else return null;
        }
        set
        {
            ViewState[Id] = value;
        }
    }

我正在使用asp:data sourse:

<asp:SqlDataSource ID="SqlDataSourceGridView" runat="server" 
   ProviderName="System.Data.SqlClient" 
   SelectCommand="SELECT [Name],[Address] FROM [Table_Emp] where Id = need to pass property value >" 
   OnSelecting="SqlDataSourceGridView_Selecting">
</asp:SqlDataSource>

我想在我的条件下传递Id.这怎么可能.

请有人帮助我.

解决方法:

在这里,看一看

 <asp:sqlDataSource ID="EmployeeDetailsSqlDataSource" 
   SelectCommand="SELECT EmployeeID, LastName, FirstName FROM Employees WHERE EmployeeID = @EmpID"

   InsertCommand="INSERT INTO Employees(LastName, FirstName) VALUES (@LastName, @FirstName); 
                  SELECT @EmpID = SCOPE_IDENTITY()"
   UpdateCommand="UPDATE Employees SET LastName=@LastName, FirstName=@FirstName 
                    WHERE EmployeeID=@EmployeeID"
   DeleteCommand="DELETE Employees WHERE EmployeeID=@EmployeeID"

   ConnectionString="<%$ConnectionStrings:NorthwindConnection %>"
   OnInserted="EmployeeDetailsSqlDataSource_OnInserted"
   RunAt="server">

   <SelectParameters>
     <asp:Parameter Name="EmpID" Type="Int32" DefaultValue="0" />
   </SelectParameters>

   <InsertParameters>
     <asp:Parameter Name="EmpID" Direction="Output" Type="Int32" DefaultValue="0" />
   </InsertParameters>

 </asp:sqlDataSource>
上一篇:SqlDataSource控件超时的困惑


下一篇:如何面对被抛弃的System.Data.OracleClient