Telerik Forums
UI for ASP.NET AJAX Forum
3 answers
255 views
Looks like if I want to export to excel I first need to bind radgrid and load to  the page and then the user does something to initiate the download.

I am trying to do the bind and export in one event. Thats why I didn't add my grid to the page, I just wanted to leverage its ability to export the data for me. I don't plan on my user ever seeing a bound radgrid.

Is something like this possible? 
public void RunReport_Click(object sender, EventArgs e)
{
    //bind a radgrid in code behind
    //export the radgrid to excel when its done binding
}

Please advise.

My data has dynamic column. I use dynamic query. The code I'm using is
       private void BuildReport(string @SpecID)
        {
            RadGrid gvTemp = new RadGrid();
            
            int db = (int)CommonFunctions.CurrentDatabase();
            DateTime StartDate = UIStartDate.SelectedDate.Value;
            DateTime EndDate = UIEndDate.SelectedDate.Value;

            using (STS32Entities ctx = new STS32Entities())
            {
                SqlConnection caConn = new SqlConnection(CaConn);
                SqlCommand caCmd = new SqlCommand("CreateDynamicQuery", caConn);
                caCmd.CommandType = CommandType.StoredProcedure;
                caCmd.Parameters.Add(new SqlParameter("@DB", db));
                //caCmd.Parameters.Add(new SqlParameter("@SeqNo", SeqNo));
                //caCmd.Parameters.Add(new SqlParameter("@DataVrsn", UIDataVersion.SelectedItem.Text));
                caCmd.Parameters.Add(new SqlParameter("@SpecID", SpecID));
                caCmd.Parameters.Add(new SqlParameter("@DateType", UIEventType.SelectedValue));
                caCmd.Parameters.Add(new SqlParameter("@StartDate", StartDate.ToShortDateString()));
                caCmd.Parameters.AddWithValue("@EndDate", EndDate.ToShortDateString());
                caCmd.Parameters.Add(new SqlParameter("@HarvestCode", UIHarvestCode.Checked));

                caConn.Open();
                SqlDataReader caRdr = caCmd.ExecuteReader();

                gvTemp.DataSource = caRdr;
                gvTemp.DataBind();
                this.Form.Controls.Add(gvTemp);
                //Download.Enabled = true;
            }
            gvTemp.ExportSettings.IgnorePaging = true;
            gvTemp.ExportSettings.FileName = "DQRecords";
            gvTemp.ExportSettings.OpenInNewWindow = true;
            gvTemp.ExportSettings.Csv.FileExtension = "xls";
            gvTemp.ExportSettings.Csv.ColumnDelimiter = GridCsvDelimiter.Comma;
            gvTemp.MasterTableView.ExportToCSV();
            gvTemp.Visible = false;
        }
Konstantin Dikov
Telerik team
 answered on 07 Nov 2014
1 answer
87 views
Hi Everyone,
I've decided to start using javascript to do some client side math instead of doing it behind code.  I started to test it out with the below page. It work but before updating RadNumericTextBox3, it throw an error message "Error: Object expected".  I look into the  browser developer tool and it throw this code "t[r](n,i)". Just to point out, Firefox and Chrome didn't display the error but when I look in the developer tool, I see the same code ""t[r](n,i)".  What am I doing wrong? How can I fix it?  PS: the radscriptmanager is in the masterpage.

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="JavaScriptTextBox.aspx.cs" Inherits="TBSWeb.Lab.JavaScriptTextBox" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
    <script type="text/javascript">
        function timesValues() {
            var radTextBox1 = $find("<%= RadNumericTextBox1.ClientID %>");
            var radTextBox2 = $find("<%= RadNumericTextBox2.ClientID %>");
            var radTextBox3 = $find("<%= RadNumericTextBox3.ClientID %>");
                if (radTextBox1.get_value() != "" || radTextBox2.get_value() != "") {
                    var total = radTextBox1.get_value() * radTextBox2.get_value();
                    radTextBox3.set_value(total);
                }
            
 
        }
     
    </script>
    </telerik:RadCodeBlock>
    <telerik:RadNumericTextBox ID="RadNumericTextBox1" runat="server">
    </telerik:RadNumericTextBox>
    <telerik:RadNumericTextBox ID="RadNumericTextBox2" runat="server">
    </telerik:RadNumericTextBox>
    <telerik:RadNumericTextBox ID="RadNumericTextBox3" runat="server">
    </telerik:RadNumericTextBox>
    <telerik:RadButton ID="btnCalculate" runat="server" Text="Calculate" OnClientClicked="timesValues()">
    </telerik:RadButton>
</asp:Content>
Anthony
Top achievements
Rank 1
 answered on 07 Nov 2014
1 answer
606 views

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.
Konstantin Dikov
Telerik team
 answered on 07 Nov 2014
1 answer
142 views
Hello Team,

I am using 2014 Q3 Asp.net controls. While using resource grouping functionality by date (vertically), the control renders misaligned cells. Please see the attached image.

I was also able to reproduce this error in a separate project. Please let me know if you want me to provide you the sample project in a support ticket.

Regards,
Hristo Valyavicharski
Telerik team
 answered on 07 Nov 2014
1 answer
64 views
If you double-click on the selected grid appreciated learn how to insert a row in another grid.

 

Konstantin Dikov
Telerik team
 answered on 07 Nov 2014
2 answers
170 views
I am trying to hide a commandItem link button based on a hiddenfiled that is in a template column inside the grid.  It keeps giving me a null value because I am assuming the grid head loads beofre the body.  So how can I hide a command item from a row in the grid.

  <CommandItemTemplate>
                                                     <asp:LinkButton ID="lnkAddDate" Text="Add Dates" CommandName="InitInsert" runat="server"></asp:LinkButton>
                                                </CommandItemTemplate>
                                                <Columns>
                                                    <telerik:GridTemplateColumn>
                                                        <ItemTemplate>
                                                            <asp:LinkButton ID="lnkDelDate" runat="server" CommandName="DelDate" CommandArgument='<%# Bind("intLeaseDateId")%>'>Delete</asp:LinkButton>
                                                            <asp:HiddenField ID="HFOccur" runat="server" Value='<%# Bind("intOcurranceId")%>' />
                                                        </ItemTemplate>
                                                    </telerik:GridTemplateColumn>
                                                    <telerik:GridEditCommandColumn HeaderText="Edit" UniqueName="EditGrid" />
                                                    <telerik:GridBoundColumn HeaderText="Start Date" DataField="dtStartDate" />
                                                    <telerik:GridBoundColumn HeaderText="End Date" DataField="dtEndDate" />
                                                </Columns>
 
 
I can find it here to hide a linkbutton that is a column in the grid, but I cannot get at the commanditem button.
 
  If (TypeOf e.Item Is GridDataItem AndAlso e.Item.OwnerTableView.Name = "LeaseDates") Then
            Dim item As GridDataItem = CType(e.Item, GridDataItem)
            Dim delete As LinkButton = DirectCast(item.FindControl("lnkDelDate"), LinkButton)
            Dim occur As HiddenField = DirectCast(item.FindControl("HFOccur"), HiddenField)
            Dim status As Integer = 2
 
            If Convert.ToInt32(occur.Value) = 5 Then
                delete.Visible = False
            End If
        End If
 
 
Atempt at the commanditem from other sources on web, but does not work.
  Protected Sub myradGrid_ItemCreated(sender As Object, e As GridItemEventArgs) Handles myradGrid.ItemCreated
        If (TypeOf e.Item Is GridCommandItem AndAlso e.Item.OwnerTableView.Name = "LeaseDates") Then
            Dim cmdItem As GridCommandItem = CType(e.Item, GridCommandItem)
            Dim btn As LinkButton = DirectCast(cmdItem.FindControl("lnkAddDate"), LinkButton)
            'Dim occur As HiddenField = DirectCast(cmdItem.FindControl("HFOccur"), HiddenField)
            'Response.Write(occur.Value)
            'Response.End()
            'If Convert.ToInt32(occur.Value) = 5 Then
            '    btn.Visible = False
            'End If
        End If
    End Sub
Eyup
Telerik team
 answered on 07 Nov 2014
1 answer
133 views
I have both of these set on my grid, e.g.

OnItemCommand="RadGrid_Application_ItemCommand" OnInsertCommand="RadGrid_Application_InsertCommand"

and on an insert, it seems both of these are being invoked, both having CommandName == RadGrid.PerformInsertCommandName (the ItemCommand is also invoked with CommandName == RadGrid.InitInsertCommandName).

For whatever reason, I was thinking that only the OnInsertCommand would be invoked for the PerformInsert. Is having both of these be invoked the expected behavior?

Eyup
Telerik team
 answered on 07 Nov 2014
1 answer
269 views
I am trying to change grouping using code behind.   I have a radgrid which depending on what the user chooses group by one element or group by two.  I attempted to do this via the code below, however when I do this the radgrid never displays any records.  I have tried to add a DataSource and Databind before and after this code but the grid never displays any records.  If I hard code the grouping on the ASPX page the records will show up although I cannot change the grouping dynamically.   Can you tell me what I am doing wrong in the code below that records would not display?

        rgPhysician.MasterTableView.GroupByExpressions.Clear()
        Dim ShowFacilities As CheckBox = ctlOptions.FindControl("cbShowFacilities")
        If ShowFacilities.Checked Then
            Dim ge1 As New Telerik.Web.UI.GridGroupByExpression
            Dim gf1 As New Telerik.Web.UI.GridGroupByField
            gf1.FieldName = "Facility"
            gf1.HeaderValueSeparator = String.Empty
            gf1.HeaderText = "Facility - "
            ge1.SelectFields.Add(gf1)
            rgPhysician.MasterTableView.GroupByExpressions.Add(ge1)

            Dim ge2 As New Telerik.Web.UI.GridGroupByExpression
            Dim gf2 As New Telerik.Web.UI.GridGroupByField
            gf2.FieldName = "Name"
            gf2.HeaderValueSeparator = String.Empty
            gf2.HeaderText = "&nbsp;"
            ge2.SelectFields.Add(gf2)
            rgPhysician.MasterTableView.GroupByExpressions.Add(ge2)
        Else
            Dim ge2 As New Telerik.Web.UI.GridGroupByExpression
            Dim gf2 As New Telerik.Web.UI.GridGroupByField
            gf2.FieldName = "Name"
            gf2.HeaderValueSeparator = String.Empty
            gf2.HeaderText = "&nbsp;"
            ge2.SelectFields.Add(gf2)
            rgPhysician.MasterTableView.GroupByExpressions.Add(ge2)
        End If   





Kostadin
Telerik team
 answered on 07 Nov 2014
1 answer
93 views
I have a radgrid, with default grouping and also has  this._RadGrid1.AllowMultiRowSelection = true;
But I am unable to select rows. Could grouping be the cause?
Eyup
Telerik team
 answered on 07 Nov 2014
1 answer
169 views
I have a form where I'm using an AutoCompleteBox to allow users to select a client from the database and create some information to attach to that client. If the client doesn't already exist, I have a quick input form on the same page that allows them to add the new client to the database. This triggers a server-side event that inserts the client info and returns the Client Name and an automatically generated Client ID that I use to create a token for AutoCompleteBox.

I'm using the OnClientEntryAdded & OnClientEntryRemoved events to control whether the Add Client form inputs are enabled or disabled. Basically, if a token exists, they cannot add a new client to the database. This works if I load a token through the AutoCompleteBox. The input fields are cleared and disabled when a token is loaded and reenabled if all tokens are removed from the AutoCompleteBox.

The issues occurs when I fire the server-side click event for the Add Client information. I insert the new record and create a token that I add to the AutoCompleteBox then the OnClientEntryAdded event automatically fires once all the server-side events are complete. The logical operator shown below in my sample script works. It correctly finds that the AutoCompleteBox now has 1 entry but then when it tries to clear and disable the textbox, it throws a null or undefined object error. The best I can determine, is that the OnClientEntryAdded is fired before the textboxes are available in the DOM but I have no idea how to workaround this. Any help is appreciated.

function NewClientInputsToggle(sender, eventArgs) {
    if ($find("<%= racClientSearch.ClientID %>").get_entries().get_count() == 0) {
        $find("<%= txtNewClient.ClientID %>").enable();
    }
    else {
        $find("<%= txtNewClient.ClientID %>").clear();
        $find("<%= txtNewClient.ClientID %>").disable();
     }
}
Nencho
Telerik team
 answered on 07 Nov 2014
Narrow your results
Selected tags
Tags
+? more
Top users last month
Shiori
Top achievements
Rank 2
Iron
Tien
Top achievements
Rank 1
Iron
Robert
Top achievements
Rank 1
Rob
Top achievements
Rank 4
Bronze
Bronze
Iron
Geoff
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Top users last month
Shiori
Top achievements
Rank 2
Iron
Tien
Top achievements
Rank 1
Iron
Robert
Top achievements
Rank 1
Rob
Top achievements
Rank 4
Bronze
Bronze
Iron
Geoff
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?