How to Change the FormView Mode Based on the Count of Records Returned by the Query

I'm trying to pass querystring via url to another page, so this page shows me the data in a FormView from some DB table where ID equals the queryString I've passed through the url, and it works just fine, exept when the table doesn't have data for that ID, which causes the FormView to be hidden.

now my question is how can I make the form view to show edit mode or insert mode, if there is no data for that ID???
tryMe2cAsked:
Who is Participating?
 
tryMe2cAuthor Commented:
it would be by using the SqlDataSource1_Selected event, which takes two parameters:
 sender of type object, and e of type  SqlDataSourceStatusEventArgs

and the Count of Records Returned by the Query, can be tested by the following line of code:
int totalRecords = e.AffectedRows;

Open in new window

of course if totalRecords == 0, then there is no data associated to that queryString, hence we change the formView mode by the following line:

FormView1.ChangeMode(FormViewMode.Insert);

Open in new window


so the whole code would be as the following:

    protected void SqlDataSource1_Selected(object sender, SqlDataSourceStatusEventArgs e)
    {
        int totalRecords = e.AffectedRows;
        if (totalRecords == 0)
            FormView1.ChangeMode(FormViewMode.Insert);
    }

Open in new window

0
 
keyuCommented:
1)  if that id is null than display  show insert button and on submit chek the id value if its null or dont exist in db simply insert the records.

2) if that id exists display data in side form fields and show edit button and on submit save the form values.
0
 
tryMe2cAuthor Commented:
Can you show me how??
0
 
tryMe2cAuthor Commented:
this kind of answers are what I'm looking for!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.