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...
-
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 }
-
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.
-
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); } }
0 comments:
Post a Comment