Page 1 of 1

Hide "+" on single record ( add button )

Posted: Wed Dec 14, 2022 5:16 am
by crash

I am using this code to hide the "+" button if there is a single record.

It is now hiding the "+" button all the time, even if there is no records.

Can anyone tell me why this is not working, or help with the code? I've tried rec count with null, but that also does not work.
I get no errors.

Thanks

// Page Load event
public void Page_Render() {
//Log("Page Render");
var rec_count = ExecuteScalar("select count(*) from <MyTable>.");
if(rec_count != "1")
{
var addlink = OtherOptions["addedit"].GetItem("add");
addlink.Visible = false;
}
}


Re: Hide "+" on single record ( add button )

Posted: Wed Dec 14, 2022 5:49 am
by MichaelG

You may want to cast your variable as integer for checking. For example:

int cnt = (int)ExecuteScalar("...");
if (cnt != 1) {
//...
}

If problem persists, open the project with VS 2022, add a break point in your codes and debug from there.


Re: Hide "+" on single record ( add button )

Posted: Tue Dec 20, 2022 1:43 am
by crash

Thanks that worked well, changed the cnt to O and the button disappears, however, I need it to count the records on the current page, or it blocks other users from adding.

I need to replace <tablename> with the current page, I've tried CurrentPage.RowCount and CurrentPage ... neither work
Can you help? Thanks

This is my working code, this hides the add button:
int cnt = (int)ExecuteScalar("select count(*) from <tablename>");
if (cnt != 0)
{
var addlink = OtherOptions["addedit"].GetItem("add");
addlink.Visible = false;
}


Re: Hide "+" on single record ( add button )

Posted: Tue Dec 20, 2022 6:22 am
by MichaelG

Do you mean you want to prevent adding for certain user or page? You can add your your codes as:

if (CurrentPageID() == "..." && CurrentUserName() == "...") {
//... Codes to hide button
}


Re: Hide "+" on single record ( add button )

Posted: Wed Dec 21, 2022 4:10 am
by crash

No... those functions work fine thanks....I'm trying to hid the button if there is more than one record on the current page.
So my row count or record count is from the current fields you see, if there is more than one row it should hide the + button or de-activate add.
Thanks


Re: Hide "+" on single record ( add button )

Posted: Wed Dec 21, 2022 10:56 am
by MichaelG

You need to get the list of all the records in the current page and build the SQL to get the total record count.


Re: Hide "+" on single record ( add button )

Posted: Thu Dec 22, 2022 6:10 am
by crash

I don't need to show the count...I just need the calculation to hide the button.

ie A rows count function for the current page if hide "+"

It needs to hide if only one record, currently ASPNetmaker allows any user to add as many records as they like, somehow this should be a standard feature as I imagine most users registering on a system will add only single records linked to their profiles.

If I link it to their ID it allows them to keep adding

Thanks


Re: Hide "+" on single record ( add button )

Posted: Thu Dec 29, 2022 5:18 am
by crash

Can anyone help me with this code, I need to get the record count of the current page.
In some case I need to hide the plus button if single record is viewable and in other cases if a maximum is shown

Thanks


Re: Hide "+" on single record ( add button )

Posted: Tue Aug 08, 2023 1:47 am
by crash

I have finally managed to get this code to to hide the add link if there is a single record.. this works on my list page... but not in view page..
How would I get this to work on the view and details view page.. thanks.

here is my code

// Page Load event
public void Page_Render() {
//Log("Page Render");

if (TotalRecords == 1)
{
var addlink = OtherOptions["addedit"].GetItem("add");
addlink.Visible = false;
}


Re: Hide "+" on single record ( add button )

Posted: Tue Aug 08, 2023 8:06 am
by MichaelG

You can simply use ListRecordCount() instead of TotalRecords.


Re: Hide "+" on single record ( add button )

Posted: Wed Aug 09, 2023 5:21 am
by crash

Where would I put this.. when I put it in Page Render I get error add link is not recognized.
Thanks very much