2009-02-27 27 views
0

我的頁面加載事件看起來是這樣的....asp.net的SqlDataSource的DetailView:如何設置適當的select語句

SqlDataSource1.ConnectionString = Connection.ConnectionStr; 

    SqlDataSource1.SelectCommand = "select firstname,lastname from customer"; 

    SqlDataSource1.InsertCommand = "CustRec_iu"; 
    SqlDataSource1.InsertCommandType = SqlDataSourceCommandType.StoredProcedure; 

    SqlDataSource1.InsertParameters.Clear(); 

    SqlDataSource1.InsertParameters.Add(new Parameter("firstname", DbType.String)); 
    SqlDataSource1.InsertParameters.Add(new Parameter("LastName", DbType.String)); 
    SqlDataSource1.InsertParameters.Add(new Parameter("Active",DbType.Int16,"1")); 

的的DetailView控制的設置是這樣的....

 <asp:DetailsView ID="dvCustDetails1" runat="server" AutoGenerateRows="False" 
      DataSourceID="SqlDataSource1" Height="149px" Width="469px" 
      OnItemInserted=dvCustDetails1_ItemInserted 

      > 
      <Fields> 
       <asp:BoundField DataField="FirstName" HeaderText="First Name" 
        SortExpression="FirstName" /> 
       <asp:BoundField DataField="LastName" HeaderText="Last Name" 
        SortExpression="LastName" /> 
       <asp:CommandField ButtonType="Button" ShowInsertButton="True" /> 
      </Fields> 
     </asp:DetailsView> 

剛剛插入功能完成後,我想從客戶表中獲取custid,這是標識列,一些如何提取它,並選擇與該記錄類似的表,如

select * from cu其中custid = @custid。

然後控件在插入後呈現後,我希望它根據上面的select語句顯示新插入的記錄。

此外,我想detailview顯示更新按鈕,所以我可以更新記錄。

我將如何實現?

我在谷歌搜索甚至打印書籍中發現了很少的文檔。

回答

0

您希望將sqldatasource的OnSelected事件與來自SQL調用的返回參數一起使用。

一下添加到SqlDataSource控件

OnSelected ="sqlds_Selected" 

,並實現它是這樣的:

protected void sqlds_Selected(object sender, SqlDataSourceStatusEventArgs e) 
{ 
    //get the command object from the arg and 
    //then you can get to the parameter value 

    e.Command.Parameters["@CustomerID"].Value 

    //then set this to your detailsview key 

} 
+0

我錯過了一些東西,但它不是爲我工作..更多信息將是有益的。 – 2009-02-27 03:43:17