This is a migrated thread and some comments may be shown as answers.

[Solved] Paging and editing fields

8 Answers 128 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ricardo
Top achievements
Rank 1
Ricardo asked on 19 Apr 2013, 03:23 PM
I have a grid connected to a datasource and one the the field is a textbox that let the user change values. I want to keep the new values thrue my pagging but everytime I do the bind or rebind the changes do not shows.

thanks in advanced.

Ricardo.

8 Answers, 1 is accepted

Sort by
0
Elliott
Top achievements
Rank 2
answered on 19 Apr 2013, 05:00 PM
Ricardo

sounds like you are (re)building your data source wrong
try using a NeedDataSource event handler
let the grid determine when it needs to be refreshed

meanwhile
some code would help the forum community help you solve your problem better....
the grid in html (or whatever it is in) - and the code used to populate it

is the textbox a result of an Edit command - or is it outside the grid?  and um are you updating the underlying data store?
0
Ricardo
Top achievements
Rank 1
answered on 19 Apr 2013, 06:05 PM
The only problem this is a old code with rad controls from 2007. here is my asp code. The field changing is txtCost.

 <radg:radgrid id="grdProducts" runat="server" autogeneratecolumns="False" OnItemDataBound="grdProducts_ItemDataBound" OnPageIndexChanged="grdProducts_PageIndexChanged" Width="500px" gridlines="None" skin="Blue" >
                                                  <PagerStyle PagerTextFormat="Cambiar de P&amp;aacute;gina: {4} &amp;nbsp;|&amp;nbsp; P&amp;aacute;gina {0} de {1},  {2} al {3} de {5}."></PagerStyle>
                                                   <MasterTableView AllowPaging="true">
                                                  <Columns>                                                      
                                                  <radG:GridBoundColumn DataField="ProductId" HeaderText="N&#250;mero de &lt;br/&gt;Identificaci&#243;n"  UniqueName="ProductId">
                                                    <HeaderStyle HorizontalAlign="Center" />
                                                    <ItemStyle HorizontalAlign="Center" />
                                                  </radG:GridBoundColumn>
                                                  <radG:GridBoundColumn DataField="Product" HeaderText="Producto" UniqueName="Product">
                                                    <HeaderStyle HorizontalAlign="Left" />
                                                    <ItemStyle HorizontalAlign="Left" />
                                                  </radG:GridBoundColumn>
                                                  <radG:GridBoundColumn DataField="UnitDescription" HeaderText="Unidad &lt;br/&gt;de Medida" UniqueName="UnitDescription">
                                                    <HeaderStyle HorizontalAlign="Center" />
                                                    <ItemStyle HorizontalAlign="Center" />
                                                  </radG:GridBoundColumn>
                                                  <radG:GridBoundColumn DataField="Category" HeaderText="Categor&#237;a" UniqueName="Category">
                                                    <HeaderStyle HorizontalAlign="Center" />
                                                    <ItemStyle HorizontalAlign="Center" />
                                                  </radG:GridBoundColumn>
                                                  <radG:GridBoundColumn DataField="SupplierCost" HeaderText="SupplierCost" Visible="False" UniqueName="SupplierCost"></radG:GridBoundColumn>
                                                  <radG:GridTemplateColumn UniqueName="TemplateColumn" HeaderText="Precio">
                                                      <HeaderStyle HorizontalAlign="Center" />
                                                      <ItemStyle HorizontalAlign="Center" />
                                                      <ItemTemplate>
                                                          <cc1:NumericTextBox ID="txtCost" AllowDecimal="true" DecimalPlaces="2" runat="server" Width="70px" style="text-align:right;"></cc1:NumericTextBox>
                                                      </ItemTemplate>
                                                    </radG:GridTemplateColumn>                                                 
                                                  </Columns>
                                                      <RowIndicatorColumn Visible="False">
                                                          <HeaderStyle Width="20px" />
                                                      </RowIndicatorColumn>
                                                      <ExpandCollapseColumn Visible="False">
                                                          <HeaderStyle Width="19px" />
                                                      </ExpandCollapseColumn>
                                                  </MasterTableView>
                                                </radg:radgrid>
0
Ricardo
Top achievements
Rank 1
answered on 19 Apr 2013, 06:19 PM
This is how my grid looks. the datatable  is in memory only and after finish then a store procedure will actually update the DB.
0
Elliott
Top achievements
Rank 2
answered on 19 Apr 2013, 06:29 PM
does you grid try (and succeed!) refreshing with each new page?  It sounds like you are not updating the repository often enough - or refreshing more than you planned
I've seen and maintained web sites (but not written any) that cache the data, then update the cache - if there is a cache use that to refresh the page, not the original data repository
0
Ricardo
Top achievements
Rank 1
answered on 19 Apr 2013, 06:34 PM
the only work with this code but the problem the values change in the grid does not update the data source.

  protected void grdProducts_PageIndexChanged(object source, GridPageChangedEventArgs e)
    {
        try
        {
            e.Item.OwnerTableView.CurrentPageIndex = e.NewPageIndex;
            BindGrid();
        }
        catch (Exception ex)
        {
            this.lblError.Text = "Un error ha ocurrido al mostrar la página:<BR>Mensaje: " + ex.Message;
        }

    }

private void BindGrid()
    {
        try
        {
            if (Session[ApplicationSessionsVariables.ProductDataTable] != null)
            {
                this.grdProducts.MasterTableView.NoMasterRecordsText = "No hay productos para mostrar.";
                this.grdProducts.DataSource = (DataTable)Session[ApplicationSessionsVariables.ProductDataTable];
                this.grdProducts.DataBind();         
            }
        }
        catch (Exception ex)
        {
            this.lblError.Text = ex.Message;
        }
    }
0
Elliott
Top achievements
Rank 2
answered on 19 Apr 2013, 06:46 PM
I hope a Telerik Admin (or an MVP) joins this thread
I really think you are trying to get around the recommended method of populating your grid
if the dataset is huge then use LinqtoSQL - I used it to build a grid with over 25K items
if you need to change the paging size you can do that, too
I have built about a dozen or more Telerik grids in the past 3 years - and only once issued a BindGrid() command, on my first effort
use the NeedDataSource event handler
- if there is no cache object, go out to the repository and get the data source - then cache the resulting dataset
if you update the data retrieve, update and replace the cache
if you update the repository replace the cache
0
Ricardo
Top achievements
Rank 1
answered on 19 Apr 2013, 06:59 PM
The only problem is that OnNeedDataSource is implemented in the newer version of telerik not 2007 version.
0
Elliott
Top achievements
Rank 2
answered on 19 Apr 2013, 07:12 PM
well then upgrade!

there is an expression here in the United States - you get what you pay for
if you want the quality of Telerik controls - then your boss should cough up the annual license fee
it will pay for itself many times over in the dollar (or peso or pound or) figure of your time saved

I can't help you - your working on a version from 3 years before I even heard of Telerik
Tags
Grid
Asked by
Ricardo
Top achievements
Rank 1
Answers by
Elliott
Top achievements
Rank 2
Ricardo
Top achievements
Rank 1
Share this question
or