Telerik Forums
UI for ASP.NET AJAX Forum
5 answers
268 views
Hi Team,
I have a radgrid which I want to export to Excel.
Columns and data in my grid, both are left aligned (please find attached images.)
But when I export the grid to excel, headers align center whereas data align left or right.
I tried with ExcelExportCellFormatting event, but got no success.

Here is my code :
protected void rgContracts_ExcelExportCellFormatting(object sender, ExcelExportCellFormattingEventArgs e)
      {
          try
          {
              GridDataItem item = e.Cell.Parent as GridDataItem;
              if (e.FormattedColumn.UniqueName == "ContractNo")
                  e.Cell.Style["Horizontal-Align"] = "Right";
              if (item.ItemType == GridItemType.Item)
                  item.Style["Horizontal-Align"] = "Left";
              if (item.ItemType == GridItemType.Header)
                  e.Cell.Style["Horizontal-Align"] = "Right";
          }
          catch (Exception ex)
          {
              XITingExceptionProcessor.ProcessException(this, ex);
          }
      }

and on button click event :
protected void btnReport_Click(object sender, EventArgs e)
       {
           try
           {
foreach (GridColumn item in rgContracts.MasterTableView.Columns)
               {
                   if ((item.UniqueName == "TemplateColumn_Select"))
                       item.Visible = false;
                   if(item.UniqueName=="Details")
                       item.Visible=false;
               }
               rgContracts.AllowSorting = false;
               rgContracts.AllowFilteringByColumn = false;
               rgContracts.ExportSettings.IgnorePaging = true;
               rgContracts.ExportSettings.OpenInNewWindow = true;
               rgContracts.ExportSettings.ExportOnlyData = true;
               rgContracts.MasterTableView.ExportToExcel();
}
           catch (Exception ex)
           {
               XITingExceptionProcessor.ProcessException(this, ex);
           }
       }

Please find attached the images of my grid and report.

Could you please help me out ??

Regards,
Lok..
Eyup
Telerik team
 answered on 25 Dec 2015
4 answers
317 views

Hello,

 I am using a "Combined" filter type on a RadGrid and some of my columns use the CheckList filter like the one shown below. 

<telerik:GridBoundColumn
    DataField="State" HeaderText="State" ReadOnly="true" HeaderStyle-Width="40px" FilterControlWidth="40px"
    ItemStyle-Width="40px" AutoPostBackOnFilter="true" UniqueName="State" SortExpression="State"
    FilterCheckListEnableLoadOnDemand="false" FilterControlAltText="Filter State column" CurrentFilterFunction="StartsWith"/>

We are using a persistence manager to restore the state of the grid, sometimes this includes values that were checked in the column above. When restoring from the persistence manager, the grid is filtered correctly however, the values are not checked in the FilterCheckList.

 I tried checking the values in the DataBound event handler for the list box and the values get selected correctly but not checked correctly.

private void ListBox_DataBound(object sender, EventArgs e)
{
    RadListBox listBox = sender as RadListBox;
    string filter = grdOpportunities.MasterTableView.FilterExpression;
    filter = filter.Replace("AND", "&");
    string[] filters = filter.Split('&');
 
    foreach (string f in filters)
    {
        if (f.Contains(listBox.DataKeyField))
        {
            string current = f.Replace("OR", "&");
            string[] options = current.Split('&');
 
            foreach (string o in options)
            {
                foreach (RadListBoxItem item in listBox.Items)
                {
                    if (o.Contains(item.DataKey.ToString()))
                    {
                        item.Selected = true;
                        item.Checked = true;
                    }
                }
            }
        }
    }
}
Attached is what I see after this code block is executed. 

Please advise, thank you!

 

Jordan
Top achievements
Rank 1
 answered on 24 Dec 2015
1 answer
265 views

I had to create a table from a MS SQL statement. The table was a product listing whose Items could be added to a shopping cart.

The table creation has to occur in the Page Init event. You should read elsewhere as to why this is a requirement.

 

Imports Telerik.Web.UI
Imports System.Data.SqlClient
 
 
Private Sub wfTelerikGrid_Init(sender As Object, e As EventArgs) Handles Me.Init
        DefineGridStructure()
End Sub
 
Private Sub DefineGridStructure()
        Dim grid As New RadGrid()
        grid.ID = "RadGrid1"
        Dim CoConn As New System.Data.SqlClient.SqlConnection
        Dim ParmString As String = String.Empty
         
        CoConn.ConnectionString = PublicVariables.WSConnInfoStringP
        ParmString = "SELECT IDNo, ItemNo, ItemDesc, Points, '' as Qty FROM WSProductDtl where WSProductIDNo = 5 "
        '
        Dim dataadapter As New SqlDataAdapter(ParmString, CoConn)
        dataadapter.SelectCommand.Parameters.Clear()
        dataadapter.SelectCommand.Parameters.AddWithValue("@IDNo", 5)
        'dataadapter.SelectCommand.Parameters.AddWithValue("@Line_No", LineNoInteger)
        'dataadapter.SelectCommand.Parameters.AddWithValue("@userID", Environment.MachineName.ToString.Trim.ToUpper & "\" & Main.GetUserName)
        Dim dt As New DataTable
        '
        CoConn.Open()
        dataadapter.Fill(dt)
        CoConn.Close()
        CoConn.Dispose()
        '
        grid.DataSource = dt
 
 
        'grid.DataSourceID = "SqlDataSource1"
 
        'grid.Skin = "Vista"
        grid.Width = Unit.Percentage(100)
        grid.PageSize = 15
        grid.AllowPaging = True
        grid.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric
        grid.AutoGenerateColumns = False
 
        'Add Customers table
        grid.MasterTableView.Width = Unit.Percentage(50)
        grid.MasterTableView.DataKeyNames = New String() {"IDNo"}
        Dim boundColumn As New GridBoundColumn()
        boundColumn.DataField = "IDNo"
        boundColumn.HeaderText = "WSProductDtl IDNo"
        boundColumn.Visible = False
        grid.MasterTableView.Columns.Add(boundColumn)
        boundColumn = New GridBoundColumn()
        boundColumn.DataField = "ItemNo"
        boundColumn.HeaderText = "Item No"
        boundColumn.HeaderStyle.Width = Unit.Percentage(20)
        boundColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Left
        grid.MasterTableView.Columns.Add(boundColumn)
        boundColumn = New GridBoundColumn
        boundColumn.DataField = "ItemDesc"
        boundColumn.HeaderText = "Item Description"
        boundColumn.HeaderStyle.Width = Unit.Percentage(50)
        boundColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Left
        grid.MasterTableView.Columns.Add(boundColumn)
        boundColumn = New GridBoundColumn
        boundColumn.DataField = "Points"
        boundColumn.HeaderText = "Points"
        boundColumn.HeaderStyle.Width = Unit.Percentage(15)
        boundColumn.HeaderStyle.HorizontalAlign = HorizontalAlign.Right
        boundColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Right
        grid.MasterTableView.Columns.Add(boundColumn)
        Dim templateColumnName As String = "Quantity"
        Dim templateColumn As New GridTemplateColumn()
        templateColumn.ItemTemplate = New MyTemplate(templateColumnName)
        templateColumn.HeaderText = templateColumnName
        templateColumn.HeaderStyle.Width = Unit.Percentage(15)
        templateColumn.HeaderStyle.HorizontalAlign = HorizontalAlign.Right
        templateColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Right
        grid.MasterTableView.Columns.Add(templateColumn)
        ' Add the grid to the placeholder
        Me.PlaceHolder1.Controls.Add(grid)
    End Sub
 
Private Class MyTemplate
        Implements ITemplate
        Protected textBox As TextBox
        Private colname As String
        Public Sub New(ByVal cName As String)
            colname = cName
   End Sub
   Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements ITemplate.InstantiateIn
            textBox = New TextBox()
            textBox.ID = "QtyTextBox"
            container.Controls.Add(textBox)
   End Sub
End Class

 One the table was created, I needed to step through the rows and read various cell values. Below is the code to do that.

Private Sub SubmitButton_Click(sender As Object, e As EventArgs) Handles SubmitButton.Click
         
        Dim RadGrid1 As RadGrid = CType(PlaceHolder1.FindControl("RadGrid1"), RadGrid)
 
        If Not (RadGrid1 Is Nothing) Then
 
            For Each item As GridDataItem In RadGrid1.MasterTableView.Items
                Dim QtyTextBox As TextBox = item.FindControl("QtyTextBox")
                Dim QtyString As String = QtyTextBox.Text
                Dim cell As TableCell = DirectCast(item("ItemNo"), TableCell)
                Dim ItemNoString As String = cell.Text
                Dim WSProductIDNoString As String = item.GetDataKeyValue("IDNo").ToString()
                '
 
            Next
 
        End If
End Sub

Perhaps I should have added  a Add to Cart button on every row. Since I didn't know how to do that I elected to use the single submit button.

I had a difficult time piecing this code together. I wanted to post it so it would be available in a single place. If there are more efficient ways of accomplishing this task, please feel free to comment.

 

 

 

 

Eyup
Telerik team
 answered on 24 Dec 2015
2 answers
190 views

Hello,

 I'm having a problem but I actually don't know if it is really a problem or if it is normal behavior.

Let's consider this:

I have a form that loads data from DB. I check IsPostBack before loading data soi dont load everything when changing the values on some controls.

When I save (a button click, and a postback) the data is all saved, and that postback didnt pass the load method, so no DB access on that life cycle part.

I guess it is ok, right?

The problem is when:

- Before i'm validating data then i ask the user something. If he confirms, then I send the .ajaxrequest() (client-side method from the AjaxManager I put on the page) and this goes for the Load method of the life cycle, and in the method, the IsPostback is false, so it access the DB.

 

The strange thing is:

Lets say on the first load (from DB) the name field was "Rob".

I changed it to "Berta" then tried saving

I was asked something then confirmed.

It entered the DB loading and brought me "Rob"

but then when the saving continued (I'm calling it from the ajaxManager serverside event that catches the client ajaxrequest method) it is "Bertha" that I entered.

 

I don't know if it is normal behavior or if I'm doing wrong for checking the IsPostback property. I'm kinda new to this ajax thing and this is making me a little confused.

 

Thanks in advance for any help

Viktor Tachev
Telerik team
 answered on 24 Dec 2015
1 answer
132 views

Hi

I wana to bind Radgrid to web service with paging server side (linq) , so How do i implement it ?

 

Viktor Tachev
Telerik team
 answered on 24 Dec 2015
4 answers
448 views
Hi I have a radgrid in batch edit mode. I've created a javascript function that is fired OnCommand to do client side validation as described here: http://www.telerik.com/forums/batch-editing---row-validation. When I open a new row for insert, put in an incorrect value and hit save, the javascript fires and set_cancel is set to true.

The issue is that after the cancel, the grid now thinks this new row is an update instead of an insert. Once the user changes the flagged cells and hits save again, the validation passes and my C# RadGrid2_UpdateCommand is hit, with a null NewValues Hashtable and an empty OldValues Hashtable.

I'm using AutomaticInsert,Update,Delete on the grid. Should the grid not retain the insert state after cancel? If not how can I handle this?
Konstantin Dikov
Telerik team
 answered on 24 Dec 2015
1 answer
74 views

We've just noticed a problem with the DropDownList in the Chrome Browser on Android devices (might effect other version).

When the web page is zoomed the position of the Drop Down moves out of alignment. The greater the zoom level the more it is out of alignment.

I've attached 2 screen shots:

  • Small_OK - standard zoom where everything is fine.
  • Zoom_Wrong - a zoomed view where the position of the drop down has moved down the screen. (Below the Asset Type drop down)

We are using the latest version of ASP.NET Ajax controls: 2015.3.1111

Let me know if you would like any further information.

Thanks,

Rob

Viktor Tachev
Telerik team
 answered on 24 Dec 2015
2 answers
221 views

I have a RadRating element for each row in a RadGrid, and need to get the associated Id for the row where the RadRating is being Rated (but with Javascript), however, the get_parent() method is returning the grid reference and not the row.

How can I get the GridDataItem of the row of the RadRating?

The following code works sometimes but not all the time. What am I doing wrong?

 

<script type="text/javascript">
    (function(global,undefined) {
 
        function OnClientRating(controlRating,args) {
            var row = controlRating.get_parent();
            var userId = row.getDataKeyValue("UserId");
        }
 
        global.OnClientRating = OnClientRating;
 
    })(window);
</script>
 
<rad:RadGrid runat="server" ID="gridUsers" Skin="Hay"
            EnableAJAX="False"
            AutoGenerateColumns="False"
            GridLines="Both"
            Width="100%"
            AllowSorting="True"
            OnItemDataBound="Grid_ItemDataBound">
    <MasterTableView DataKeyNames="UserId" ClientDataKeyNames="UserId">
        <Columns>
            <rad:GridTemplateColumn HeaderText="Name" HeaderStyle-Width="180px" ItemStyle-Width="180px">
                <ItemTemplate>
                    <%# Eval("FullName")%>
                </ItemTemplate>
            </rad:GridTemplateColumn>
            <rad:GridTemplateColumn HeaderText="Rating" HeaderStyle-Width="100px" ItemStyle-Width="100px">
                <ItemTemplate>
                    <rad:RadRating ID="ratAppraiserRating" runat="server" ItemCount="5" Value='<%# Eval("AverageRating")%>'
                        SelectionMode="Continuous" Precision="Item" Orientation="Horizontal" OnClientRating="OnClientRating"
                        OnRate="RatRating_Rate" AutoPostBack="true" />
                </ItemTemplate>
            </rad:GridTemplateColumn>
            </Columns>
    </MasterTableView>
    <ClientSettings>
        <Scrolling UseStaticHeaders="false" ScrollHeight="240px"  AllowScroll="true"  />
        <Selecting AllowRowSelect="false" />
        <ClientEvents OnRowDblClick="selectRow" />
    </ClientSettings>
</rad:RadGrid>

Viktor Tachev
Telerik team
 answered on 24 Dec 2015
4 answers
1.2K+ views
I am trying to do validation on my multiPages which are part of my radtabStrip on each click of the radtab.  I am trying to the get the selected index of each tab so that I know which one I am on to do the validation.

I must say I give the new site and F, what a frustrating new site.

<telerik:RadTabStrip ID="radESGRTab" runat="server" Orientation="HorizontalTop" MultiPageID="radPageMulti" ClickSelectedTab="true" Skin="Web20" Font-Bold="true" Font-Size="Large" Width="800px" OnClientMouseOver="tabEmployer" OnClientTabSelected="CheckValidation">
              <Tabs>
                  <telerik:RadTab PageViewID="rdPageInfo" Text="Soldier Info" runat="server" SelectedIndex="1"></telerik:RadTab>
                  <telerik:RadTab PageViewID="rdPageEmploy" Text="Employer Info" runat="server" SelectedIndex="2"></telerik:RadTab>
                  <telerik:RadTab PageViewID="rdpageSurvey" Text="Survey Info" SelectedIndex="3"></telerik:RadTab>
                  <telerik:RadTab PageViewID="rdPageAwards" Text="Employer Awards" SelectedIndex="4"></telerik:RadTab>
              </Tabs>
          </telerik:RadTabStrip>



function CheckValidation() {
           var tab1 = $find('<%=radESGRTab.ClientID %>').selectedIndex();
            
           if (tab1 == 1) {
               var combo = $find('<%= ddlSoldCounty.ClientID %>');
               var item = combo.get_selectedItem().get_value();
               alert(combo.get_selectedItem().get_value());
               if (item == 1) {
                   alert('You must pick a county from Drop Down List');
               }
           }
       }
   </script>
Ivan Danchev
Telerik team
 answered on 24 Dec 2015
1 answer
1.0K+ views

Hi

I want to refresh/rebind all child grids (child2 gridtableview) on edit/insert case of chid1 (gridtableview), child1 and chid2 are on same level in Detail tables of RadGrid.

I am using update command function to insert/edit records in chid1.

After completing insert/edit case of child1 gridview rebind automatically while the other child2 on same level contain old data, i want to refresh/rebind the child2 grid as well.

Here is code structure for understanding... 

 

<telerik:RadGrid ID="PlEmployee" runat="server" AllowPaging="True" AllowSorting="True" AllowFilteringByColumn="True"

OnUpdateCommand="PlEmployee_UpdateCommand"

<DetailTables> 

    <telerik:GridTableView runat="server" Name="Child1">

     <telerik:GridTableView runat="server" Name="Child2">  

 </DetailTables>

 </telerik:RadGrid>

 

Regards,

Zain

Vasil
Telerik team
 answered on 24 Dec 2015
Narrow your results
Selected tags
Tags
+? more
Top users last month
Will
Top achievements
Rank 2
Iron
Motti
Top achievements
Rank 1
Iron
Hester
Top achievements
Rank 1
Iron
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Thomas
Top achievements
Rank 2
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Will
Top achievements
Rank 2
Iron
Motti
Top achievements
Rank 1
Iron
Hester
Top achievements
Rank 1
Iron
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Thomas
Top achievements
Rank 2
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?