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

DataGrid Cannot Load Data after call Response.Redirect()

3 Answers 155 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Pham
Top achievements
Rank 1
Pham asked on 08 Aug 2011, 08:52 AM
Hi, everybody! I have a problem when I load data to DataGrid. I have a web page and a RadFormDecorator, when I click a button in RadFormDecorator, I want data in RadFormDecorator will update to database and update in DataGrid. I call Response.Redirect("MyWeb.aspx") but DataGrid in MyWeb can't update. My code:

protected void Page_Load(object sender, EventArgs e)
        {       
            if (!Page.IsPostBack)
            {
                 
                 
                SqlDataAdapter da = new SqlDataAdapter();
                ds = new DataSet();
                DataTable dt = new DataTable();
                SqlConnection conn = new SqlConnection(connectionString);
                SqlCommand cmd = new SqlCommand();
           
                conn.Open();
 
            
                try
                {                   
                    cmd = conn.CreateCommand();
                    cmd.CommandType = CommandType.StoredProcedure;
                  
                    cmd.CommandText = "MyStored";                 
                    da.SelectCommand = cmd;
                    ds.Tables.Clear();
                    ds.Clear();
                    ds.AcceptChanges();
                    da.Fill(ds);
                    Session.Clear();                   
                    Session.Add("Source", ds);
                    radgrid.DataSource = null;
                    radgrid.DataSource = ds.Tables[0];
                    radgrid.DataBind();                                      
                     
                }
                catch
                {
                }
                conn.Close();

            }
        }

When I call Response.Redirect("MyWeb.aspx"), dataset changed but Radgrid not changed? Thanks!
         

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 08 Aug 2011, 09:42 AM
Hello Ducanh,

I suppose this issue arises because you are binding the grid using simple data binding. Make sure that you use Advanced data binding using NeedDataSource event to handle complex operations like update, delete, paging etc. Check the following help documentation which explains more about this.
Advanced Data-binding (using NeedDataSource event).

Thanks,
Princy
0
Pham
Top achievements
Rank 1
answered on 08 Aug 2011, 03:35 PM
Thanks Princy. However, I did it that way but result don't change. My radgrid change only when I press Enter link on web browser, radgrid cannot auto update when I call Response.Redirect("MyWeb.aspx") from event click button of RadDecorateForm (This form called as form Client of Web Page). I do another way, create a button in this web page,after I updated data in form RadDecorateForm, I do returnToParent() function: update database and close form RadDecorate; I click this button I call Response.Redirect("MyWeb.aspx") , result radgrid cant update. But this way is not good for my project. Have you any idea? Thanks you!  My code I do as your way:
protected void Page_Load(object sender, EventArgs e)
       {
           if (!Page.IsPostBack)
           {
               radgrid.DataBind();
           }
       }      
        
       protected void radgrid_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
       {          
           {
               RadTreeNode TreeNode = RadTreeView.SelectedNode;
               SqlDataAdapter da = new SqlDataAdapter();
               ds = new DataSet();
               DataTable dt = new DataTable();
               SqlConnection conn = new SqlConnection(connectionString);
               SqlCommand cmd = new SqlCommand();
               //Mo ket noi
               conn.Open();
               //Thuc hien load du lieu
               try
               {
                   cmd = conn.CreateCommand();
                   cmd.CommandType = CommandType.StoredProcedure;
                   cmd.Parameters.AddWithValue(@"MA_DVIQLY", "302");
                   cmd.CommandText = "[dbo].[pda_selectFull_DDO]";
                   da.SelectCommand = cmd;
                   da.Fill(ds, "GNDIEM_DO");
                   da.Fill(dt);
                   conn.Close();
                   Session.Clear();
                   Session.Add("Source", ds);
                   radgrid.DataSource = dt;                
               }
               catch (Exception ex)
               {
                   MessageBox.Show(ex.Message);
               }               
           }
       }
0
Pham
Top achievements
Rank 1
answered on 10 Aug 2011, 10:18 AM
Thanks Princy!
I found a way. RadGrid update only when I call Response.Redirect() function in web page; if I call Response.Redirect() function in RadWindow, RadGrid cannot update!
Tags
Grid
Asked by
Pham
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Pham
Top achievements
Rank 1
Share this question
or