dotnet-practitioner
dotnet-practitioner

Reputation: 14148

detailsview: automatic invoke insert or edit mode

Table structure is as follows:

id int identity
firstname varchar(100) 
lastname varchar(100)

I have an detailsview control that displays/inserts/updates firstname lastname on profile.aspx page.

If customer lands on this page with id in querystring then I want it to load that record into detailsview via sqldatasource and have edit button enabled.

If customer lands on this page with out id in querystring then I want it to display blanks for first/lastname record into detailsview via sqldatasource and have insert button enabled.

How do I accomplish that???

Please help...

Upvotes: 1

Views: 6498

Answers (3)

Jordan Johnson
Jordan Johnson

Reputation: 253

In your Page_Load set a condition

Page_Load
{

check query string and find empID

If (empID != null)
{

detailsView1.ChangeMode(DetailsViewMode.Edit);
}
else
{


detailsView1.ChangeMode(DetailsViewMode.Insert);
}

}

Upvotes: 1

Dhaust
Dhaust

Reputation: 5550

Use this method to pop your DetailsView into edit mode if there is an ID passed in:

    Dim theID As Int32 = Request.QueryString("id")
    If Not theID Is Nothing Then
        SqlDataSource.SelectParameters("THE_ID").DefaultValue = theID
        SqlDataSource.DataBind()
        DetailsView.ChangeMode(DetailsViewMode.Edit)
    End If  

Just do some additional tweaking for the 'no ID passed in' case.

Upvotes: 1

Andrew Clark
Andrew Clark

Reputation: 1403

Read this Update Databases using ASP.NET 2.0 SqlDataSource

Use the following code to check to see if there is an id passed in if there is populate the fields with his data.

int EmpID = 0;

if (Request.Querystring.Get("EmpID") != null) 
{ 
    id = Page.Request.QueryString["EmpID"];
    //load your values
}

Upvotes: 0

Related Questions