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

Grid Control has null value when firing event

1 Answer 76 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Qiang
Top achievements
Rank 1
Qiang asked on 31 Oct 2008, 09:52 PM
Hello guys,

This is my first post on this forum. I got a null GridControl value when I fire a event.

I have a RadGrid and a button control on a page. When I click the button I want a event to be fired in order to bring up export method to export the grid contents into a Excel file. But when I click the button, I always get null value for the GridControl property of Sender.

Here is the code:
<%@ Page Language="C#" MasterPageFile="~/Templates/Site.master" AutoEventWireup="true" CodeFile="SupplierSearch.aspx.cs" Inherits="ApprovedSupplier_SupplierSearch" Title="Global Quality Web" %> 
<%@ Register TagPrefix="uc" TagName="DatePicker" Src="~/UserControls/Common/DatePicker.ascx" %> 
<%@ Register TagPrefix="uc" TagName="Attachments" Src="~/UserControls/Common/AttachmentControl.ascx" %> 
<%@ Register TagPrefix="uc" TagName="LookupBase" Src="~/UserControls/Common/LookupBase.ascx" %> 
<%@ Register TagPrefix="uc" TagName="DateTimePicker" Src="~/UserControls/Common/DatePicker.ascx" %> 
<%@ Register TagPrefix="uc" TagName="SnapControl" Src="~/UserControls/Common/SnapControl.ascx" %> 
<%@ Register TagPrefix="uc" TagName="ExportPanel" Src="~/UserControls/Common/ExportPanel.ascx" %> 
 
<asp:Content ID="Content1" ContentPlaceHolderID="SiteContentHolder" Runat="Server">  
<script type="text/javascript">  
function onClickSupplierId(id) {  
    var url = 'SuppAppReq.aspx?id=' + id;  
    if(window.parent) {  
        window.parent.location.href = url;  
    }  
    else {  
        window.location.href = url;  
    }  
}  
 
function onClickDeleteSupplier(id) {  
    if(confirm("Do you really want to delete record " + id + " ?")) {  
        var url = 'SupplierSearch.aspx?isDeleted=true&id=' + id;  
        if(window.parent) {  
            window.parent.location.href = url;  
        }  
        else {  
            window.location.href = url;  
        }  
    }  
}  
 
 
</script> 
    <div id="qsButtons" runat="server" visible="false">  
        <asp:ImageButton ID="btnNewSupplier" OnClientClick="ShowProgressBar();" OnClick="btnNewSupplier_OnClick"  Runat="Server" ImageUrl="~/Images/NOV/Menu/NOVaddNewSupplier.gif" AlternateText="New Location" ImageAlign="AbsMiddle"/>  
        <asp:ImageButton ID="btnAdvancedSearch" OnClientClick="ShowProgressBar();" OnClick="btnAdvancedSearch_OnClick"  Runat="Server" ImageUrl="~/Images/NOV/Menu/NOVadvSch.gif" AlternateText="Advanced Search" ImageAlign="AbsMiddle"/>          
    </div> 
 
    <div id="Filters" class="IFrameFilters"></div> 
        <uc:SnapControl ID="SnapControl" DivID="Filters" Text="Supplier Filters" runat="server">  
            <Content> 
                <table border="0" cellpadding="4" cellspacing="2">  
                    <tr> 
                        <td>Legal Name:</td> 
                        <td><asp:TextBox ID="txtLegalName" runat="server"></asp:TextBox></td>  
                        <td>Supplier Title:</td> 
                        <td><asp:TextBox ID="txtSupplierTitle" runat="server"></asp:TextBox></td>  
                        <td>Supplier Email:</td> 
                        <td><asp:TextBox ID="txtSupplierEmail" runat="server"></asp:TextBox></td>  
                    </tr> 
                    <tr> 
                        <td>ERP Supplier No:</td> 
                        <td><asp:TextBox ID="txtERPSupplierNumber" runat="server"></asp:TextBox></td>  
                        <td>Business Unit:</td> 
                        <td><asp:TextBox ID="txtBusinessUnit" runat="server"></asp:TextBox></td>  
                        <td>Number Machinists:</td> 
                        <td><asp:TextBox ID="txtNumMachinists" runat="server"></asp:TextBox></td>  
                    </tr> 
                    <tr> 
                        <td>Manual Machines:</td> 
                        <td><asp:TextBox ID="txtManualMachines" runat="server"></asp:TextBox></td>  
                        <td>Number Shifts:</td> 
                        <td><asp:TextBox ID="txtNumShifts" runat="server"></asp:TextBox></td>  
                        <td>Number CNC:</td> 
                        <td><asp:TextBox ID="txtNumCNC" runat="server"></asp:TextBox></td>  
                    </tr> 
                    <tr> 
                        <td>Type of service:</td> 
                        <td><asp:TextBox ID="txtTypeSvc" runat="server" /></td>  
                        <td>Date Cap Update:</td> 
                        <td><uc:DatePicker ID="txtDateCapUdate" runat="server" AllowClear="true" /></td>  
                        <td>Supplier Category:</td> 
                        <td><asp:TextBox ID="txtSupplierCategory" runat="server"></asp:TextBox></td>  
                    </tr> 
                    <tr> 
                        <td>Approval Status:</td> 
                        <td> 
                        <asp:DropDownList ID="ddlApprovalStatus" runat="server" > 
                        <asp:ListItem Value="" Text="[All]" /> 
                        <asp:ListItem Value="0" Text="Being Reviewed" /> 
                        <asp:ListItem Value="1" Text="Approved" /> 
                        <asp:ListItem Value="2" Text="Suspended" /> 
                        </asp:DropDownList> 
                        </td> 
                        <td>Approval Method:</td> 
                        <td><asp:TextBox ID="txtApprovalMethod" runat="server" /></td>  
                    </tr> 
                    <tr> 
                        <td colspan="6">  
                            <asp:ImageButton ID="btnFilter" OnClientClick="ShowProgressBar();" Runat="Server" ImageUrl="~/Images/NOV/Menu/NOVfilter.gif" AlternateText="Filter" ImageAlign="AbsMiddle"/>                                      
                            <asp:ImageButton ID="btnAddNew" OnClick="btnNewSupplier_OnClick" OnClientClick="ShowProgressBar();" Runat="Server" ImageUrl="~/Images/NOV/Menu/NOVaddNewSupplier.gif" AlternateText="Add Location" ImageAlign="AbsMiddle"/>                                                      
                        </td> 
                    </tr> 
                    <tr> 
                        <td colspan="6">  
                            <asp:Label ID="Label1" Text="To perform a search with wildcards use a *. For example, to search for everything that starts with B, use B*.<br/><br/>To search for an exact string, surround the string in quotes.  For example, to search for Asia Pacific, use &quot;Asia Pacific&quot;." ForeColor="red" runat="server"></asp:Label> 
                        </td> 
                    </tr> 
                </table> 
            </Content> 
        </uc:SnapControl> 
        <br /> 
          
        <rad:RadGrid ID="grdSupplier" runat="server" DataSourceID="dsSupplier" 
            AutoGenerateColumns="false" AllowPaging="true" AllowSorting="true" 
            PageSize="50" Width="99.8%" OnDataBound="RadGrid_DataBound" OnItemCreated="RadGrid_Setup">  
            <MasterTableView> 
                <Columns> 
                    <rad:GridHyperLinkColumn DataTextField="SupplierName" HeaderText="Supplier Name" SortExpression="SupplierName" DataNavigateUrlFormatString="javascript:onClickSupplierId('{0}');" DataNavigateUrlFields="SupplierId"></rad:GridHyperLinkColumn> 
                    <rad:GridBoundColumn DataField="BusinessUnit" HeaderText="Business Unit" SortExpression="BusinessUnit"></rad:GridBoundColumn> 
                    <rad:GridBoundColumn DataField="ERPSupplierNum" HeaderText="ERP Supplier No" SortExpression="ERPSupplierNum"></rad:GridBoundColumn> 
                    <rad:GridBoundColumn DataField="DateCapUpdate" HeaderText="Date Cap Update" SortExpression="DateCapUpdate"></rad:GridBoundColumn> 
                    <rad:GridBoundColumn DataField="ApprovalMethod" HeaderText="ApprovalMethod" SortExpression="ApprovalMethod"></rad:GridBoundColumn> 
                    <rad:GridBoundColumn DataField="Notes" HeaderText="Notes" SortExpression="Notes"></rad:GridBoundColumn> 
                    <rad:GridHyperLinkColumn Text="delete" HeaderText="delete" DataNavigateUrlFormatString="javascript:onClickDeleteSupplier('{0}');" DataNavigateUrlFields="SupplierId" ItemStyle-Width="50"></rad:GridHyperLinkColumn> 
                </Columns> 
            </MasterTableView> 
        </rad:RadGrid> 
         

 

       <uc:ExportPanel ID="ExportPanel" OnExcelExportClick="Click_ExcelExport" runat="server" /> 

 

          
        <c:SupplierDataSource ID="dsSupplier" runat="server" Sort="SupplierName" SelectMethod="GetPaged">  
            <Parameters> 
                <asp:ControlParameter Name="WhereClause" ControlID="__Page" PropertyName="WhereClause" /> 
            </Parameters> 
        </c:SupplierDataSource> 
</asp:Content> 
 
 

The code capturing the event is like this:
    public virtual void Click_ExcelExport(object sender, EventArgs e)  
    {  
        ExportGrid(sender, e, true);  
    } 

When I debug, the sender contains a null value in GridControl property.

Regards,

Qiang




1 Answer, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 04 Nov 2008, 07:20 AM
Hello Qiang,

You can call the grdSupplier.MasterTableView.ExportToExcel(); method directly to export the control's data.

Kind regards,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Qiang
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Share this question
or