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

Bind Empty DataSource To RadGrid

1 Answer 432 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Swapnil
Top achievements
Rank 1
Swapnil asked on 05 Nov 2014, 12:57 PM

Hi, 
i am having radgrid which i want to bind to empty datasource but not working i tried the code:  
function ClearItems1()
{
var RadGridTaskActivity = $find("<%= RadGridTaskActivity.ClientID %>").get_masterTableView();
masterTable.set_dataSource(string.Empty);
masterTable.dataBind();
}


i tried with string.empty OR [ ] OR null but nothing working.

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 07 Nov 2014, 03:35 PM
Hello Swapnil,

The RadGrid MasterTableView is assigned to the RadGridTaskActivity variable, but on the next lines you are using an undefined masterTable variable, so you need to change masterTable with RadGridTaskActivity.

For your convenience, following is a simple demonstration of the desired functionality:
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
    <script type="text/javascript">
        function pageLoad() {
            var data = [{ "ID": 1, "Text": "Text1" }, { "ID": 2, "Text": "Text2" }];
            var mtv = $find("RadGrid1").get_masterTableView(); mtv.set_dataSource(data); mtv.dataBind();
        }
 
        function ClearItems1() {
            var masterTable = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
            masterTable.set_dataSource([]);
            masterTable.dataBind();
        }
    </script>
</telerik:RadCodeBlock>
 
<telerik:RadGrid runat="server" ID="RadGrid1" AutoGenerateColumns="false">
    <MasterTableView>
        <Columns>
            <telerik:GridBoundColumn DataField="ID" HeaderText="ID">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Text" HeaderText="Text">
            </telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
    <ClientSettings>
        <ClientEvents OnCommand="function(){}" />
    </ClientSettings>
</telerik:RadGrid>
 
<telerik:RadButton runat="server" ID="RadButton1" AutoPostBack="false" Text="Clear data" OnClientClicked="ClearItems1"></telerik:RadButton>

Hope this helps.


Regards,
Konstantin Dikov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Swapnil
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or