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

[Solved] Clear the label Text after exporting to excel

1 Answer 144 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Srinivas Nilagiri
Top achievements
Rank 1
Srinivas Nilagiri asked on 28 Dec 2009, 04:21 AM

Hi All,
I have a RadGrid and a lable as shown below.

<telerik:AjaxSetting AjaxControlID="grdOverdue">  
        <UpdatedControls> 
            <telerik:AjaxUpdatedControl ControlID="grdOverdue"/>              
            <telerik:AjaxUpdatedControl ControlID="lblError"/>    
        </UpdatedControls> 
</telerik:AjaxSetting>     
<asp:Label ID="lblError" runat="server" Text="" Visible="false" SkinID="Error"></asp:Label>    
    <telerik:RadGrid ID="grdOverdue" runat="server"   
            ....  
            <CommandItemTemplate> 
                    <span style="float:left;margin-left:5px;">  
                        <asp:Label ID="lblJobCount" runat="server" Text=""></asp:Label> 
                    </span> 
                    <span style="float:right;margin-right:5px;">                          
                       <asp:LinkButton ID="lbExportAll" runat="server" CommandName="ExportToExcel">Export All</asp:LinkButton>&nbsp;&nbsp;  | &nbsp;&nbsp;  
                       <asp:LinkButton ID="lbExportSelected" runat="server" CommandName="ExportSelectedToExcel">  Export Selected</asp:LinkButton>                     
                   </span> 
               </CommandItemTemplate> 
               ....  
</telerik:RadGrid> 

and in the grdOverdue_ItemCommand event I am displaying error message if the user has not selected atleast one item in the grid.
protected void grdOverdue_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)  
    {  
      
        if (e.CommandName == "ExportSelectedToExcel")  
        {  
            if (selectedJobs.Count == 0)  
            {  
                lblError.Visible = true;  
                lblError.Text = "Please select atleast one job to export.";        
            }  
            else{  
                lblError.Visible = false// this is not working.  
            }  
          
        }  
    } 

Please suggest how to clear the error message and make the label invisible? Thank you.

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 28 Dec 2009, 06:54 AM
Hello Srinivas,

I tried the same scenario at my end and it seems to work. Here's the code that i tried:
c#:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    {         
        if (e.CommandName == "ExportSelectedToExcel"
        { 
            GridItemCollection selectedJobs = (GridItemCollection)RadGrid1.SelectedItems; 
            if (selectedJobs.Count == 0) 
            { 
                lblError.Visible = true
                lblError.Text = "Please select atleast one job to export."
            } 
            else 
            { 
                lblError.Visible = false;  
            } 
        } 
    } 

Make sure that the selectedJobs collection count returns a value greater than zero when a selection is made in your grid.

Thanks
Princy.
Tags
Grid
Asked by
Srinivas Nilagiri
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or