Welcome Guest Search | Active Topics | Sign In | Register

Initial values when creating a new grid row Options
James
Posted: Friday, December 19, 2008 9:02:01 AM
Rank: Member
Groups: Member

Joined: 10/4/2008
Posts: 28
How can I define initial default values when a new row is created in the grid?
eo_support
Posted: Friday, December 19, 2008 5:54:15 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

You would set the Grid cell's value. For example, you can do this on the server side to set the value of the first cell of the second row:

Code: HTML/ASPX
Grid1.Items[1].Cells[0].Value = "abc";


Or this on the client side:

Code: JavaScript
eo_GetObject("Grid1").getItem(1).getCell(0).setValue("abc");


The above syntax should work with all rows, regardless whether they are new or not.

Thanks
James
Posted: Friday, December 19, 2008 7:05:07 PM
Rank: Member
Groups: Member

Joined: 10/4/2008
Posts: 28
But I won't know the row index for the new row. How do I get the row index for only a new row?
eo_support
Posted: Saturday, December 20, 2008 5:25:41 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

The new row index = row count - 1. If you do it on the server side, you would get row count with grid.Items.Count. On the client side you would call getItemCount. You can find server side reference here:

http://www.essentialobjects.com/ViewDoc.aspx?t=EO.Web.Grid.html

And more information about how to use our client side interface at here:

http://www.essentialobjects.com/ViewDoc.aspx?t=clientapi_howto.html

Thanks
James
Posted: Sunday, December 21, 2008 4:25:39 PM
Rank: Member
Groups: Member

Joined: 10/4/2008
Posts: 28
What event can I use? The only event I see is OnItemAdded, but I can find no documentation for that event. It would be much more helpful if you could give a complete example instead on on line response.
eo_support
Posted: Sunday, December 21, 2008 5:29:09 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

We generally do not give complete code examples for user specific scenarios except for those that are already in our sample projects. The reason because doing so would encourage our users to ignore our existing samples and documentations and always ask us to provide complete sample code, which would inevitably lead us to code for them and it is obviously not something that we do. As a result, our support focuses on point you the right direction so that you know where to look. We do not code or debug for you. You may wish to take a look of our official support policy here:

http://www.essentialobjects.com/Forum/Default.aspx?g=posts&t=1368

In the case of adding item and initializing values, first you need to be very clear about how you are going to implement adding item. If you are adding item through your own code, then you do not need any event because you can initialize the cells right when you add the item. If you let the Grid to add it for you, you will need to rely on OnItemAdded event. However that is a server side event. The documentation for this event is here:

http://www.essentialobjects.com/ViewDoc.aspx?t=EO.Web.Grid.ItemAdded.html

Our documentation is generated from source code. So it should not be possible that you see a property or event but do not see the documentation for that event/property. In addition to the reference section, you should always go through the guide section for the corresponding controls. For the Grid controls, they are the topics under "EO.Web Grid".

If you have any more questions, please try to provide more specific information such as what you are trying to do, how you planed to do it, what they road blocks are, etc. For general questions like “How do I do this”, we will only tell you what are the available options. You will need to evaluation each option and decide whether they will work for you and implement. We do not provide complete ready to use solutions.

Thanks
James
Posted: Sunday, December 21, 2008 7:28:25 PM
Rank: Member
Groups: Member

Joined: 10/4/2008
Posts: 28
OK let's try this again.....

This is the code for my grid....

<eo:Grid ID="Grid1" runat="server" BorderColor="Black" BorderWidth="1px" ColumnHeaderAscImage="00050403" ColumnHeaderDescImage="00050404"
ColumnHeaderDividerImage="00050402" ColumnHeaderDividerOffset="6" ColumnHeaderHeight="18" FixedColumnCount="1" Font-Bold="False"
Font-Italic="False" Font-Names="Verdana" Font-Overline="False" Font-Size="8pt" Font-Strikeout="False" Font-Underline="False" GridLineColor="240, 240, 240"
GridLines="Both" Height="400px" ItemHeight="18" Width="1200px" FullRowMode="False" AllowNewItem="True" PageSize="40">


Since I have set AllowNewItem="True", there is a blank row at the bottom of the grid for adding a new row. If changes are made to that row then it can be saved as a new row in my database. Is it possible to have default values such as "1" in that row at the bottom of the grid? If so, how do I do it? I'm not looking for you to write my code, just give a complete enough answer that I can actually get something to work.


eo_support
Posted: Monday, December 22, 2008 6:43:59 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

The following sequence describes what happens when you add new items with AllowNewItem:

1. Automatically add a blank item to the end of the grid when you click the last row. There is no way you can set the default value here;
2. User can then edit the blank item or leave it blank;
3. User can repeat step 1 and 2 multiple times;
4. The page is submitted to the server, for example, by a separate button;
5. Your server side ItemAdded event is fired once for each newly added item;
6. You would usually handle the event and save each added items into your database. The Grid does not automatically save any changes to your DB for you;
7. You reload the Grid from the DB;
8. The whole page reloads;

You can apply your default values on step 6 before you save them to the DB. That way once the Grid reloads from the DB, user will see the default values on step 8.

Hope this helps.

Thanks!
ixthnar
Posted: Friday, August 27, 2010 10:38:43 AM
Rank: Advanced Member
Groups: Member

Joined: 11/15/2008
Posts: 44
I am trying to initialize the new rowserver
In a Grid control ...
1. eo:Grid has AllowNewItem="true" and RunningMode="Client" (have tried Server)
2. datasource has 5 records
3. in the server-side prerender event there are 5 rows
4. the actual grid has 6 rows with the last row being the "new" row
5. I want to modify that "new" row server-side

I cannot find a server-side context where the Items.Count is 6 with Items[5] being the "new" row. This is at odds with what I read in this thread.

Thoughts? Advise?

Thanks,
Chris
eo_support
Posted: Friday, August 27, 2010 11:48:16 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

You can not modify that row on the server side. That row is a temporary row on the client side only. Once user modifies it on the client side, the temp row becomes a new row. Only after that and you submit the page your server side will see this new row (the 6th row). At this point another temp row has already been created (the 7th row).

In short, your server side code will never see the last row whose sole purpose is to act as a temp row for user to add new rows.

Thanks
James
Posted: Friday, August 27, 2010 4:58:16 PM
Rank: Member
Groups: Member

Joined: 10/4/2008
Posts: 28
So the final answer to the original question is ... You can't.
eo_support
Posted: Friday, August 27, 2010 5:09:29 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
James wrote:
So the final answer to the original question is ... You can't.


Hi,

That is not entirely true. You can do it on the client side with JavaScript. But you can not do it on the server side because the server side won't see that row until the page is submitted.

Thanks


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.