Web Wiz
Home
Home
Hosting Services
Hosting Services
Knowledgebase
Knowledgebase
Community and Support Forums
Support Forums
Customer Login
Customer Login

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

Web Wiz Web Hosting 30 Day Free Trial

Windows Hosting 30 Day Free Trial, with no obligation, on all our Windows Web and Reseller Hosting Packages.

For moreĀ informationĀ see our Windows Hosting 30 Day Free Trial page.

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
  Share Topic   

Forum Jump Forum Permissions View Drop Down



Become a Fan on Facebook Follow us on Twitter Web Wiz on Google+ Community Forums Web Wiz Blogs Web Wiz News
Company Information | Contact Web Wiz | Terms & Conditions | Privacy Policy

Prices exclude VAT unless otherwise stated - $, € prices shown as a guideline only
Web Wiz Ltd, Unit 10E Dawkins Road Ind. Est, Poole, Dorset, UK, BH15 4JD
Copyright ©2001-2012 Web Wiz - All rights reserved