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

Telerik rag grid data refresh error after edit

7 Answers 105 Views
Grid
This is a migrated thread and some comments may be shown as answers.
lakmal
Top achievements
Rank 2
lakmal asked on 24 Aug 2009, 06:01 PM

Hi,

I using telerik grid with templateform for add and edit data. When i edit data or add data i cant see changes until restart page.

I load data in following method

protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            FillGrid();         
        }
    }

    void FillGrid()
    {
        CompanyControler Com = new CompanyControler();
        RadGrid1.DataSource = Com.CompanyList();
        RadGrid1.DataBind();

    }

After edit i load data like this

protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
    {
        Minute.Company Com = new Minute.Company();
        CompanyControler ComCon= new CompanyControler ();
        if (e.Item is GridEditFormItem)
        {
            GridEditFormItem item = (GridEditFormItem)e.Item;

           if( item.ItemIndex>0)                         
            {
                int id = Convert.ToInt32(item.GetDataKeyValue("CompanyID"));
                if (id != 0)
                {
                    Com.CompanyID = id;

                }
            }

            TextBox txtCompanyCode = (TextBox)e.Item.FindControl("txtCompanyCode");
            TextBox txtCompanyName = (TextBox)e.Item.FindControl("txtCompanyName");
            TextBox txtAddressLine01 = (TextBox)e.Item.FindControl("txtAdd1");
            TextBox txtAddressLine02 = (TextBox)e.Item.FindControl("txtAdd2");
            TextBox txtAddressLine03 = (TextBox)e.Item.FindControl("txtAdd3");
            TextBox txtAddressLine04 = (TextBox)e.Item.FindControl("txtAdd4");
            TextBox txtPostCode = (TextBox)e.Item.FindControl("txtPostCode");
            TextBox txtCountry = (TextBox)e.Item.FindControl("txtCountry");
            TextBox txtTelephone = (TextBox)e.Item.FindControl("txtTelephone");

            TextBox txtFax = (TextBox)e.Item.FindControl("txtFax");
            TextBox txtWeb = (TextBox)e.Item.FindControl("txtWeb");
          
            Com.CompanyCode = txtCompanyCode.Text;
            Com.CompanyName = txtCompanyName.Text;
            Com.AddressLine01 = txtAddressLine01.Text;
            Com.AddressLine02 = txtAddressLine02.Text;
            Com.AddressLine03 = txtAddressLine03.Text;
            Com.AddressLine04 = txtAddressLine04.Text;
            Com.PostCode = txtPostCode.Text;
            Com.Telephone = txtTelephone.Text;
            Com.Web = txtWeb.Text;
            Com.Fax = txtFax.Text;
            Com.Country = txtCountry.Text;
        }        
        
        if (e.CommandName == RadGrid.InitInsertCommandName ) //"Add new" button clicked
        {
            GridEditCommandColumn editColumn = (GridEditCommandColumn)RadGrid1.MasterTableView.GetColumn("EditCommandColumn");
            editColumn.Visible = false;
           
        }
        else if (e.CommandName == RadGrid.RebindGridCommandName && e.Item.OwnerTableView.IsItemInserted)
        {
            e.Canceled = true;
        }
        else
        {
            GridEditCommandColumn editColumn = (GridEditCommandColumn)RadGrid1.MasterTableView.GetColumn("EditCommandColumn");
            if (!editColumn.Visible)
                editColumn.Visible = true;            
        }

        if( e.CommandName=="PerformInsert")
            ComCon.InsertCompany(Com);

        if (e.CommandName == "Update")
        {
            ComCon.UpdateCompany(Com);
          
           
        }
      //  RadGrid1.Rebind();
        FillGrid();
       
    }

Where is error?

krds

lakmal

7 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 26 Aug 2009, 03:02 PM
Hello lak,

Probably because of this:

 else if (e.CommandName == RadGrid.RebindGridCommandName && e.Item.OwnerTableView.IsItemInserted) 
        { 
            e.Canceled = true
        } 


Sincerely yours,
Veli
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
lakmal
Top achievements
Rank 2
answered on 27 Aug 2009, 06:48 AM
I have remark that code. But still problem is there

lakmal
0
Veli
Telerik team
answered on 28 Aug 2009, 06:51 AM
Hi lak,

Ok, try advanced databinding using the NeedDataSource event:

Advanced Databinding

In your case:

protected void RadGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs args) 
    CompanyControler Com = new CompanyControler(); 
    RadGrid1.DataSource = Com.CompanyList(); 

Remove the code from Page_Load and use RadGrid.Rebind() method to rebind grid at the end if ItemCommand.

Kind regards,
Veli
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
lakmal
Top achievements
Rank 2
answered on 28 Aug 2009, 08:51 AM
Hi,

I have change my code like below. But still i cannot see new values after edit. When i refresh only i can see new values. I am using telerik trial version. Is it effect to this?


<asp:ScriptManager ID="ScriptManager1" runat="server">
     </asp:ScriptManager>   
     <p id="divMsgs" runat="server">
      <asp:Label ID="Label1" runat="server" EnableViewState="False" Font-Bold="True" ForeColor="#FF8080"></asp:Label>
      <asp:Label ID="Label2" runat="server" EnableViewState="False" Font-Bold="True" ForeColor="#00C000"></asp:Label>
     </p>
    
         <br />
    <div id="500">   
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"
            DefaultLoadingPanelID="RadAjaxLoadingPanel1">
        </telerik:RadAjaxManager>   
         <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
            <script type="text/javascript">
            function RowDblClick(sender, eventArgs)
            {
              sender.get_masterTableView().editItem(eventArgs.get_itemIndexHierarchical());
            }
            </script>

        </telerik:RadCodeBlock>
       
        <telerik:RadGrid ID="RadGrid1" runat="server" GridLines="None"
            AllowPaging="True"
            ShowStatusBar="True"
            AutoGenerateColumns="False"
            Skin="Vista" AllowCustomPaging="True"
            oninsertcommand="RadGrid1_InsertCommand"
            onupdatecommand="RadGrid1_UpdateCommand"           
            ondeletecommand="RadGrid1_DeleteCommand" onprerender="RadGrid1_PreRender"
            onneeddatasource="RadGrid1_NeedDataSource">
           
            <ValidationSettings EnableValidation="False" />
           
        <MasterTableView CommandItemDisplay="TopAndBottom"  EditMode="EditForms"
                DataKeyNames="CompanyID"  HorizontalAlign="NotSet"
                AutoGenerateColumns="False"
                allowcustompaging="False" allownaturalsort="False" >       
            <Columns>            
             <telerik:GridEditCommandColumn
                    UniqueName="EditCommandColumn" ButtonType="ImageButton" >
                </telerik:GridEditCommandColumn>               
            <telerik:GridBoundColumn DataField="CompanyCode" HeaderText="CompanyCode"
                    UniqueName="CompanyCode" >
                </telerik:GridBoundColumn>               
                      <telerik:GridBoundColumn DataField="CompanyName" HeaderText="CompanyName"
                    UniqueName="CompanyName">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="AddressLine01" HeaderText="AddressLine01"
                    UniqueName="AddressLine01">
                </telerik:GridBoundColumn>              
                <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete"
                    ConfirmDialogType="RadWindow" ConfirmText="Are you sure delete this record?" Text="Delete" UniqueName="column">
                </telerik:GridButtonColumn>
            </Columns>           
              <EditFormSettings EditFormType="Template">                 
              <EditColumn UniqueName="EditCommandColumn" ButtonType="ImageButton">               
                </EditColumn>                 
                    <FormTemplate>                   
                    <table id="Table2" cellspacing="2" cellpadding="1"  border="0" rules="none"
                            style="border-collapse: collapse; background: white;">
                       
                        <tr>
                             <td>
                                    <table >
                                            <tr>
                                                <td>
                                                <b>Company Code</b>
                                                </td>                                               
                                                <td>                                               
                                                    <asp:TextBox ID="txtCompanyCode" Text='<%# Bind("CompanyCode") %>' runat="server"></asp:TextBox>
                                                </td>
                                            </tr>
                                           
                                               <tr>
                                                <td>
                                                <b>CompanyName</b>
                                               
                                                </td>
                                               
                                                <td>
                                                  <asp:TextBox ID="txtCompanyName" Text='<%# Bind("CompanyName") %>' runat="server"></asp:TextBox>

                                                </td>
                                           
                                           
                                            </tr>
                                           
                                               <tr>
                                                <td>
                                                 <b>AddressLine01</b>
                                                </td>                                               
                                                <td>                                               
                                                         <asp:TextBox ID="txtAdd1" Text='<%# Bind("AddressLine01") %>' runat="server"></asp:TextBox>
                                                </td>
                                            </tr>
                                           
                                              <tr>
                                                <td>
                                                 <b>AddressLine02</b>
                                                </td>                                               
                                                <td>
                                               
                                                         <asp:TextBox ID="txtAdd2" Text='<%# Bind("AddressLine02") %>' runat="server"></asp:TextBox>

                                                </td>                                          
                                           
                                            </tr>
                                           
                                                <tr>
                                                <td>
                                                 <b>AddressLine03</b>
                                                </td>                                               
                                                <td>
                                               
                                                         <asp:TextBox ID="txtAdd3" Text='<%# Bind("AddressLine03") %>' runat="server"></asp:TextBox>

                                                </td>
                                            </tr>
                                             <tr>
                                                <td>
                                                 <b>AddressLine04</b>
                                                </td>                                               
                                                <td>                                               
                                                         <asp:TextBox ID="txtAdd4" Text='<%# Bind("AddressLine04") %>' runat="server"></asp:TextBox>

                                                </td>
                                            </tr>
                                   
                                    </table>
                               
                                </td>
                               
                                <td>
                               
                                <table>
                                     <tr>
                                                <td>
                                                 <b>Post Code</b>
                                                </td>                                               
                                                <td>                                               
                                                         <asp:TextBox ID="txtPostCode" Text='<%# Bind("Postcode") %>' runat="server"></asp:TextBox>
                                                </td>
                                            </tr>
                                             <tr>
                                                <td>
                                                 <b>Country</b>
                                                </td>                                               
                                                <td>
                                               
                                                         <asp:TextBox ID="txtCountry" Text='<%# Bind("Country") %>' runat="server"></asp:TextBox>

                                                </td>
                                            </tr>                                           
                                 <tr>
                                                <td>
                                                 <b>Telephone</b>
                                                </td>
                                                <td>
                                               
                                                         <asp:TextBox ID="txtTelephone" Text='<%# Bind("Telephone") %>' runat="server"></asp:TextBox>

                                                </td>
                                            </tr>
                                           
                                             <tr>
                                                <td>
                                                 <b>Fax</b>
                                                </td>                                               
                                                <td>                                               
                                                         <asp:TextBox ID="txtFax" Text='<%# Bind("Fax") %>' runat="server"></asp:TextBox>

                                                </td>
                                            </tr>
                                             <tr>
                                                <td>
                                                 <b>Web</b>
                                                </td>
                                                <td>                                               
                                                         <asp:TextBox ID="txtWeb" Text='<%# Bind("Web") %>' runat="server"></asp:TextBox>

                                                </td>
                                            </tr>
                                           
                                             <tr>
                                                <td>
                                                 <b>Default</b>
                                                </td>
                                               
                                                <td>
                                                    <asp:CheckBox ID="chkDefault" Text='<%# Bind("default") %>' runat="server" />                                                     

                                                </td>
                                            </tr>  
                                </table>
                                </td>
                        </tr>                  
                           <tr>
                           <td>
                          
                           </td>
                                <td align="right" colspan="2">
                                    <asp:Button ID="btnUpdate" CausesValidation="False" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                                        runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>
                                     </asp:Button>&nbsp;
<asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False"
CommandName="Cancel"></asp:Button>

        </td>
      </tr>
    </table>
                  
        </FormTemplate>
       </EditFormSettings>                   
           
    </MasterTableView>
     <ClientSettings>
                <ClientEvents OnRowDblClick="RowDblClick" />
            </ClientSettings>
           
</telerik:RadGrid>
   
    </div>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" Runat="server"
        Skin="Default">
    </telerik:RadAjaxLoadingPanel>



 

protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e)

 

{

 

try

 

{

 

Minute.

Company Com = new Minute.Company();

 

 

CompanyControler ComCon = new CompanyControler();

 

 

if (e.Item is GridEditFormItem)

 

{

 

GridEditFormItem item = (GridEditFormItem)e.Item;

 

 

if (item.ItemIndex > 0)

 

{

 

int id = Convert.ToInt32(item.GetDataKeyValue("CompanyID"));

 

 

if (id != 0)

 

{

Com.CompanyID = id;

}

}

 

TextBox txtCompanyCode = (TextBox)e.Item.FindControl("txtCompanyCode");

 

 

TextBox txtCompanyName = (TextBox)e.Item.FindControl("txtCompanyName");

 

 

TextBox txtAddressLine01 = (TextBox)e.Item.FindControl("txtAdd1");

 

 

TextBox txtAddressLine02 = (TextBox)e.Item.FindControl("txtAdd2");

 

 

TextBox txtAddressLine03 = (TextBox)e.Item.FindControl("txtAdd3");

 

 

TextBox txtAddressLine04 = (TextBox)e.Item.FindControl("txtAdd4");

 

 

TextBox txtPostCode = (TextBox)e.Item.FindControl("txtPostCode");

 

 

TextBox txtCountry = (TextBox)e.Item.FindControl("txtCountry");

 

 

TextBox txtTelephone = (TextBox)e.Item.FindControl("txtTelephone");

 

 

TextBox txtFax = (TextBox)e.Item.FindControl("txtFax");

 

 

TextBox txtWeb = (TextBox)e.Item.FindControl("txtWeb");

 

Com.CompanyCode = txtCompanyCode.Text;

Com.CompanyName = txtCompanyName.Text;

Com.AddressLine01 = txtAddressLine01.Text;

Com.AddressLine02 = txtAddressLine02.Text;

Com.AddressLine03 = txtAddressLine03.Text;

Com.AddressLine04 = txtAddressLine04.Text;

Com.PostCode = txtPostCode.Text;

Com.Telephone = txtTelephone.Text;

Com.Web = txtWeb.Text;

Com.Fax = txtFax.Text;

Com.Country = txtCountry.Text;

}

ComCon.UpdateCompany(Com);

RadGrid1.MasterTableView.Rebind();

RadGrid1.Rebind();

 

//DisplayMessage(false, "Company " + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["CompanyID"] + " updated");

 

 

}

 

catch (Exception er)

 

{

}

}

 

protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e)

 

{

Minute.

Company Com = new Minute.Company();

 

 

CompanyControler ComCon = new CompanyControler();

 

 

 

TextBox txtCompanyCode = (TextBox)e.Item.FindControl("txtCompanyCode");

 

 

TextBox txtCompanyName = (TextBox)e.Item.FindControl("txtCompanyName");

 

 

TextBox txtAddressLine01 = (TextBox)e.Item.FindControl("txtAdd1");

 

 

TextBox txtAddressLine02 = (TextBox)e.Item.FindControl("txtAdd2");

 

 

TextBox txtAddressLine03 = (TextBox)e.Item.FindControl("txtAdd3");

 

 

TextBox txtAddressLine04 = (TextBox)e.Item.FindControl("txtAdd4");

 

 

TextBox txtPostCode = (TextBox)e.Item.FindControl("txtPostCode");

 

 

TextBox txtCountry = (TextBox)e.Item.FindControl("txtCountry");

 

 

TextBox txtTelephone = (TextBox)e.Item.FindControl("txtTelephone");

 

 

TextBox txtFax = (TextBox)e.Item.FindControl("txtFax");

 

 

TextBox txtWeb = (TextBox)e.Item.FindControl("txtWeb");

 

Com.CompanyCode = txtCompanyCode.Text;

Com.CompanyName = txtCompanyName.Text;

Com.AddressLine01 = txtAddressLine01.Text;

Com.AddressLine02 = txtAddressLine02.Text;

Com.AddressLine03 = txtAddressLine03.Text;

Com.AddressLine04 = txtAddressLine04.Text;

Com.PostCode = txtPostCode.Text;

Com.Telephone = txtTelephone.Text;

Com.Web = txtWeb.Text;

Com.Fax = txtFax.Text;

Com.Country = txtCountry.Text;

 

ComCon.InsertCompany (Com);

DisplayMessage(

false, "Company inserted");

 

RadGrid1.MasterTableView.Rebind();

RadGrid1.Rebind();

 

 

}

 

protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)

 

{

 

CompanyControler Com = new CompanyControler();

 

RadGrid1.DataSource = Com.CompanyList();

 

}

 

protected void RadGrid1_PreRender(object sender, EventArgs e)

 

{

 

if (!this.IsPostBack)

 

{

 

this.RadGrid1.MasterTableView.Items[1].Edit = true;

 

 

this.RadGrid1.MasterTableView.Rebind();

 

}

}

 

protected void RadGrid1_DeleteCommand(object source, GridCommandEventArgs e)

 

{

Minute.

Company Com = new Minute.Company();

 

 

CompanyControler ComCon = new CompanyControler();

 

 

int ID = int.Parse(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["CompanyID"].ToString());

 

Com.CompanyID = ID;

ComCon.DeleteCompany (Com);

 

//e.Canceled = true;

 

RadGrid1.MasterTableView.Rebind();

RadGrid1.Rebind();

 

 

 

}


0
Veli
Telerik team
answered on 31 Aug 2009, 08:31 AM
Hi lak,

No, the trial version of RadControls is fully functional and only differ from the dev version by the trial notification you occasionally get.

Your code actually seems OK now, and I wonder why is your grid not updated right after insert/update. If you can open a regular support ticket, and provide us a sample runnable project we can test to reproduce this issue, we can better assist you with the solution.

Greetings,
Veli
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
lakmal
Top achievements
Rank 2
answered on 31 Aug 2009, 09:07 AM
hi,

This errors comming with MS Access database. I put all the table to MSSQL database and test it its working fine.

I think this is telerik bug with MSACCESS databse.

Anyhow i chnage database and solve my issue. Thanks your support

lakmal
0
Veli
Telerik team
answered on 31 Aug 2009, 10:20 AM
Hi lak,

RadGrid does not run any logic particular to MS Access files. Its databinding logic is general and common for all supported data sources. Anyway, I am glad your were able to solve this issue.

Good luck.

Sincerely yours,
Veli
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
lakmal
Top achievements
Rank 2
Answers by
Veli
Telerik team
lakmal
Top achievements
Rank 2
Share this question
or