views:

693

answers:

1

My page load event looks like this....

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

The detailview control setting looks like this....

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

Right after insert functionality is done, I would like to capture the custid from customer table which is identity column, some how extract it and select table with that record like

select * from customer where custid = @custid.

Then after the control renders after insert, I would like it to show the newly inserted record based on the above select statement.

Also, I would like detailsview to show update button so I could update the record.

How would i accomplish that??

I find very little documentation out there in google search or even print books.

A: 

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

}
Mcbeev
I am missing some thing but its not working for me.. more information would be helpful.
dotnet-practitioner