views:

196

answers:

2

hi

i am using formview and sqldatasouce. every thing is fine but when i have no record in my table nothing(no formview) is shown on the page. i want that when my table has no record then formview should be shown but in Insert Mod.

can any body help me to resolve this?

thanks in advance

+1  A: 

Use the FormView.ChangeMode() method to switch your form over to Insert mode.

Some code might look like this.

myFormView.DataBind();

if (myFormView.CurrentMode != FormViewMode.Insert)
{
   if (myFormView.DataItem == null)
   {
       myFormView.ChangeMode(FormViewMode.Insert);
   }  
}
womp
+1  A: 

It should be like...

if (!Page.IsPostBack)
    {
        if (FormView1.DataItemCount == 0)
        {
            FormView1.ChangeMode(FormViewMode.Insert);
        }
    }
Muhammad Akhtar
thanks for the help
Shahid Mahmood Adil