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

[Solved] Radgrid not rebinding

3 Answers 189 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Armin
Top achievements
Rank 1
Armin asked on 24 Jun 2014, 08:37 PM
I have a scenario like this. I want the radgrid inside the radwindow to refresh everytime it opens, but right not after the initial random values are set to the radgrid, every time I reopen the radwindow, the radgrid table stays the same. Is there any way to achieve what I want?
<div>
    <telerik:RadWindowManager ID="RadWindowManager1" runat="server" EnableShadow="true" EnableViewState="false">
        <Windows>
            <telerik:RadWindow ID="BatchIdSelectorPopup" runat="server" Width="360px" Height="360px" Modal="true">
                <ContentTemplate>
                    <telerik:RadGrid runat="server" ID="BatchIdSelectionGrid" AllowPaging="true" AllowSorting="true" OnNeedDataSource="BatchIdSelectionGrid_NeedDataSource">
                        <MasterTableView AutoGenerateColumns="false">
                            <Columns>
                                <telerik:GridBoundColumn DataField="BatchId" HeaderText="Batch Ids" UniqueName="BatchId"></telerik:GridBoundColumn>
                            </Columns>
                        </MasterTableView>
                    </telerik:RadGrid>
                </ContentTemplate>
            </telerik:RadWindow>
        </Windows>
    </telerik:RadWindowManager>
</div>
 
 
<telerik:RadButton ID="btnSelectBatchIds" Text="Select Batch Ids" runat="server" OnClick="btnSelectBatchIds_Click"/>
 
 
 
 
 
protected void Page_Load(object sender, EventArgs e)
    {
        BatchIdSelectorPopup.OpenerElementID = btnSelectBatchIds.ClientID;
    }
 
    protected void btnSelectBatchIds_Click(object sender, EventArgs e)
    {
        BatchIdSelectionGrid.Rebind();
    }
     
    protected void BatchIdSelectionGrid_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("BatchId", typeof(int));
        Random rnd = new Random();
        dt.Rows.Add(rnd.Next(1, 1000));
        dt.Rows.Add(rnd.Next(1, 1000));
        dt.Rows.Add(rnd.Next(1, 1000));
        dt.Rows.Add(rnd.Next(1, 1000));
        dt.Rows.Add(rnd.Next(1, 1000));
        dt.Rows.Add(rnd.Next(1, 1000));
        dt.Rows.Add(rnd.Next(1, 1000));
        dt.Rows.Add(rnd.Next(1, 1000));
        BatchIdSelectionGrid.DataSource = dt;
    }



3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 25 Jun 2014, 05:55 AM
Hi Armin,

Please try to Rebind the Grid in the OnLoad event of the RadWindow.

ASPX:
<telerik:RadWindow ID="BatchIdSelectorPopup" runat="server" OnLoad="BatchIdSelectorPopup_Load". .>

C#:
protected void BatchIdSelectorPopup_Load(object sender, EventArgs e)
{
  BatchIdSelectionGrid.Rebind();
}

Thanks,
Princy
0
Armin
Top achievements
Rank 1
answered on 25 Jun 2014, 01:57 PM
Hi.
I tried what you suggested and the values in the grid are still remaining the same from the initial bind.
0
Princy
Top achievements
Rank 2
answered on 26 Jun 2014, 04:52 AM
Hi Armin,

In order the Grid to Rebind it needs a postback, when you set OpenerElementID property, there is no postback hence the grid is unable to bind. You can show the window on the Button click event as shown below and bind the Grid in the button click.

C#:
protected void btnSelectBatchIds_Click(object sender, EventArgs e)
{       
 BatchIdSelectionGrid.Rebind();
//Use this instead of BatchIdSelectorPopup.OpenerElementID to open window
 BatchIdSelectorPopup.VisibleOnPageLoad = true;
}

Thanks,
Princy
Tags
Grid
Asked by
Armin
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Armin
Top achievements
Rank 1
Share this question
or