Web Wiz Forums Homepage
Forum Home Forum Home - General Discussion - ASP.NET Discussion
  New Posts New Posts RSS Feed - FormView: Change DefaultMode Insert on empty data
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

FormView: Change DefaultMode Insert on empty data

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

Joined: 21 March 2003
Location: United Kingdom
Status: Offline
Posts: 165
Points: 168
Post Options Post Options   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
Posts: 3
Points: 3
Post Options Post Options   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
Posts: 165
Points: 168
Post Options Post Options   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

Bulletin Board Software by Web Wiz Forums® version 10 alpha build 20092001
Copyright ©2001-2009 Web Wiz

This page was generated in 0.071 seconds.