![]() |
FormView: Change DefaultMode Insert on empty data |
Post Reply
|
| Author | |
PrivateEye
Groupie
Joined: 21 March 2003 Location: United Kingdom Status: Offline Posts: 165 Points: 168 |
Post Options
Quote Reply
Topic: FormView: Change DefaultMode Insert on empty dataPosted: 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.
|
|
![]() |
|
mpdotnet
Newbie
Joined: 31 July 2009 Status: Offline Posts: 3 Points: 3 |
Post Options
Quote Reply
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.)
|
|
![]() |
|
PrivateEye
Groupie
Joined: 21 March 2003 Location: United Kingdom Status: Offline Posts: 165 Points: 168 |
Post Options
Quote Reply
Posted: 14 September 2009 at 5:28pm |
|
I needed the code in VB.Net but C# is also understandable you know
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
|
|
![]() |
|
Post Reply
|
| Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |