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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tryMe2cAuthor Commented:
this kind of answers are what I'm looking for!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.