Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - FormView: Change DefaultMode Insert on empty data
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

FormView: Change DefaultMode Insert on empty data

 Post Reply Post Reply
Author
PrivateEye View Drop Down
Groupie
Groupie
Avatar

Joined: 21 March 2003
Location: United Kingdom
Status: Offline
Points: 168
Post Options Post Options   Thanks (0) Thanks(0)   Quote PrivateEye Quote  Post ReplyReply Direct Link To This Post Topic: FormView: Change DefaultMode Insert on empty data
    Posted: 13 September 2009 at 11:17am

Good day to all!

I am using FormView on my asp.net page where users can add data. The problem is that when no data is present in the SQL Server table, by default "Insert" link button is not displayed. So users can't insert data in this scnario. I want FormView control to be in "Insert" mode when no data is present in table and when there is data, its mode should be "ReadOnly". Can anyone please help me to solve this problem. Many thanks in advance.
Back to Top
mpdotnet View Drop Down
Newbie
Newbie


Joined: 31 July 2009
Status: Offline
Points: 7
Post Options Post Options   Thanks (0) Thanks(0)   Quote mpdotnet Quote  Post ReplyReply Direct Link To This Post Posted: 13 September 2009 at 12:41pm
Good day!
 
Try this:
 
 
protected void FormView1_DataBound(object sender, EventArgs e)
{
    if (FormView1.DataItemCount == 0)
        FormView1.ChangeMode(FormViewMode.Insert);
}
 
If that doesn't work, try the SqlDataSource Selected event:
 
 
...
 
if (e.AffectedRows < 1)
{
    FormView1.ChangeMode(FormViewMode.Insert);
}
else
{
    FormView1.ChangeMode(FormViewMode.Edit);
}
 
Hope this helps. I haven't tested it.  
 
Regards,
mp
 
(As a newbie, my posts are delayed pendng approval.)
 
Back to Top
PrivateEye View Drop Down
Groupie
Groupie
Avatar

Joined: 21 March 2003
Location: United Kingdom
Status: Offline
Points: 168
Post Options Post Options   Thanks (0) Thanks(0)   Quote PrivateEye Quote  Post ReplyReply Direct Link To This Post Posted: 14 September 2009 at 5:28pm
I needed the code in VB.Net but C# is also understandable you know Smile Thank you for the support. I have not tested your suggestions. However, I copied new link button code from ItemTemplate to EmptyDataTempate like this:

<EmptyDataTemplate>
                    No data found.<br />
                    <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False"
                        CommandName="New" Text="New" />
</EmptyDataTemplate>

and It is working. I am not sure that my approach is professional or not, any idea?
The Judgement Day
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.