Inserting a new Row in a Details View when the dataset is empy

Discussion in 'ASP.NET / ASP.NET Core' started by VTA_Admin, Oct 4, 2008.

  1. I am unable to find a way using the DetailsView control to add a new row when the table is empty.

    Is there an easy solution to this?

    Thanks.
     
  2. I think it is more complex that that.


    I found the issue. It seems that a detailsview has a defaultmode of ReadOnly. When presented with an empty table in ReadOnly mode, it displays a blank.


    The trick is to change the mode of the detailsview to insert if the table is empty before the view displayed.


    Oneperson on the asp.net forum suggested that you do the following:





    protected void DetailsView1_OnDataBound(object sender, EventArgs e)


    {


    if (DetailsView1.PageCount <1)


    {


    DetailsView1.ChangeMode(DetailsViewMode.Insert);


    }


    }





    This command does the trick, but I still can't get it to fire before the page loads. If you use an OnDataBound method like the one above, do you have to reference it anywhere within the DetailsView control?

    Post Edited (VTA Admin) : 10/5/2008 1:31:00 AM GMT
     
  3. Well I found it. You have to define the OnDataBound parameter to the method.


    It works fine.


    Thanks for the help. Sorry for the false alarm.
     
  4. Good job [​IMG]
     

Share This Page