0

我的页面加载事件看起来像这样......

    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 customer where custid = @custid。

然后在插入后控件呈现后,我希望它根据上面的选择语句显示新插入的记录。

另外,我希望 detailsview 显示更新按钮,以便我可以更新记录。

我将如何做到这一点?

我在谷歌搜索甚至印刷书籍中发现的文档很少。

4

1 回答 1

0

You want to use the sqldatasource's OnSelected event with a return parameter from the SQL call.

Add this to the sqldatasource

OnSelected ="sqlds_Selected"

and implement it something like:

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

}
于 2009-02-27T03:04:52.177 回答