Telerik Forums
UI for ASP.NET AJAX Forum
1 answer
225 views
Hello,
I have a RadGrid that has it's columns programatically defined and initial data (via a dataset) loaded in the Page_Init event.  The RadGrid is created and the initial data is loaded correctly, however when I try to insert new data into the grid the initial data is lost.

Example:  The RadGrid is created with two columns and a data set with five rows of data.  When I click "Add record" to add "Paul, Allen" the original five rows of data are removed and only the newest record, e.g. "Paul, Allen" in this example, is retained when I need all six records.

I was using the following documentation as a guide to creating the RadGrid's columns in the code-behing, http://www.telerik.com/help/aspnet-ajax/grdchanginggridstructuredynamically.html, and as such I have set  EnableColumnViewState.  I am thinking this is part of the problem and I'm having trouble figuring out when and where to store the dataset to a Session or ViewState object.

<telerik:RadGrid ID="RadGrid1" runat="server" > 
    <MasterTableView> 
        <RowIndicatorColumn> 
            <HeaderStyle Width="20px" /> 
        </RowIndicatorColumn> 
        <ExpandCollapseColumn> 
            <HeaderStyle Width="20px" /> 
        </ExpandCollapseColumn> 
         <Columns> 
         </Columns> 
 
    </MasterTableView> 
    <ClientSettings AllowKeyboardNavigation="True"
        <Scrolling AllowScroll="True" UseStaticHeaders="True" ScrollHeight="" /> 
    </ClientSettings> 
</telerik:RadGrid> 


Imports Microsoft.ApplicationBlocks.Data 
Imports System.Configuration 
Imports System.Data.SqlClient 
Imports System.Data 
Imports Telerik.Web.UI 
 
 
Partial Class Usercontrols_Grid 
    Inherits System.Web.UI.UserControl 
 
    Private _customDataSet As DataSet 
 
    
    Private Sub CreateGrid() 
        'RadGrid1.PageSize = 10 
        RadGrid1.AllowPaging = True 
        RadGrid1.AllowSorting = True 
        RadGrid1.GridLines = GridLines.None 
        RadGrid1.Width = Unit.Percentage(50) 
        RadGrid1.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric 
        RadGrid1.AutoGenerateColumns = False 
        RadGrid1.ShowStatusBar = False 
        RadGrid1.PageSize = 7 
 
        'RadGrid1.MasterTableView.Width = Unit.Percentage(100) 
        RadGrid1.MasterTableView.EnableColumnsViewState = False 
        RadGrid1.MasterTableView.PageSize = 5 
        RadGrid1.MasterTableView.EditMode = GridEditMode.PopUp 
        RadGrid1.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top 
        RadGrid1.MasterTableView.DataKeyNames = New String() {"CustomID"
        RadGrid1.MasterTableView.EditFormSettings.EditColumn.ButtonType = GridButtonColumnType.ImageButton 
        RadGrid1.MasterTableView.EditFormSettings.PopUpSettings.Modal = True 
 
        'RadAjaxManager1.AjaxSettings.AddAjaxSetting(RadGrid1, RadGrid1) 
    End Sub 
 
    Private Sub CreateColumns() 
        Dim EditColumn As New GridEditCommandColumn 
        EditColumn.ButtonType = GridButtonColumnType.ImageButton 
        EditColumn.UniqueName = System.Guid.NewGuid.ToString 
 
        Dim DeleteColumn As New GridButtonColumn 
        DeleteColumn.ConfirmText = "Delete this row?" 
        DeleteColumn.ConfirmDialogType = GridConfirmDialogType.RadWindow 
        DeleteColumn.ConfirmTitle = "Delete" 
        DeleteColumn.ButtonType = GridButtonColumnType.ImageButton 
        DeleteColumn.CommandName = "Delete" 
        DeleteColumn.Text = "Delete" 
        DeleteColumn.UniqueName = "DeleteColumn" 
        DeleteColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Center 
 
 
        With RadGrid1.MasterTableView.Columns 
            .Add(EditColumn) 
            If Not IsNothing(_customDataSet) Then 
                For Each dc As DataColumn In _customDataSet.Tables(0).Columns 
                    Dim NewColumn = GetGridColumnType(dc.DataType.ToString) 
NewColumn.GetType.ToString) 
 
                    'Dim NewColumn As New GridBoundColumn 
                    NewColumn.DataField = dc.ColumnName 
                    NewColumn.HeaderText = dc.ColumnName 
                    If dc.ColumnName <> "CustomID" Then 
                        .Add(NewColumn) 
                    End If 
                Next 
            End If 
            .Add(DeleteColumn) 
        End With 
 
    End Sub 
 
    Private Property GridSource() As DataSet 
        Get 
            Dim obj As Object = Me.ViewState("_gds"
            If (Not (obj) Is NothingThen 
                Return CType(obj, DataSet) 
            Else 
                _customDataSet = CreateDataSetStructure() 
                Me.ViewState("_gds") = _customDataSet 
                Return _customDataSet 
            End If 
        End Get 
        Set(ByVal value As DataSet) 
            Me.ViewState("_gds") = value 
            _customDataSet = value 
        End Set 
    End Property 
 
    
     'Created initial data set 
    Private Function CreateDataSetStructure() As DataSet 
     'Internals removed for posting as this part works fine to load the initial data set structure 
 
        Return CustomDataSet 
 
    End Function 
 
    Protected Sub Page_Init(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Init 
        RadGrid1.DataSource = GridSource 
        CreateGrid() 
        CreateColumns() 
    End Sub 
 
     
 
    Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load 
  
    End Sub 
 
 
 
    Protected Sub RadGrid1_InsertCommand(ByVal source As ObjectByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.InsertCommand 
        Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem) 
        Dim editMan As GridEditManager = editedItem.EditManager 
 
        Dim CustomTable As DataTable = GridSource.Tables(0) 
        Dim NewRow As DataRow 
        NewRow = CustomTable.NewRow() 
 
        'Set new values 
        Dim column As GridColumn 
        For Each column In e.Item.OwnerTableView.Columns 
            If TypeOf column Is IGridEditableColumn Then 
                Dim editableCol As IGridEditableColumn = CType(column, IGridEditableColumn) 
 
                If (editableCol.IsEditable) Then 
                    Dim editor As IGridColumnEditor = editMan.GetColumnEditor(editableCol) 
                    Dim editorText As String = "Unknown" 
                    Dim editorValue As Object = Nothing 
                    If (TypeOf editor Is GridTextColumnEditor) Then 
                        editorText = CType(editor, GridTextColumnEditor).Text 
                        editorValue = CType(editor, GridTextColumnEditor).Text 
                    End If 
                    If (TypeOf editor Is GridNumericColumnEditor) Then 
                        editorText = CType(editor, GridNumericColumnEditor).Text 
                        editorValue = CType(editor, GridNumericColumnEditor).Text 
                    End If 
                    If (TypeOf editor Is GridDateTimeColumnEditor) Then 
                        editorText = CType(editor, GridDateTimeColumnEditor).Text 
                        editorValue = CType(editor, GridDateTimeColumnEditor).Text 
                    End If 
                    If (TypeOf editor Is GridBoolColumnEditor) Then 
                        editorText = CType(editor, GridBoolColumnEditor).Value.ToString() 
                        editorValue = CType(editor, GridBoolColumnEditor).Value 
                    End If 
                    If (TypeOf editor Is GridDropDownColumnEditor) Then 
                        editorText = CType(editor, GridDropDownColumnEditor).SelectedText + "; " + CType(editor, GridDropDownColumnEditor).SelectedValue 
                        editorValue = CType(editor, GridDropDownColumnEditor).SelectedValue 
                    End If 
                    Try 
                        newRow(column.UniqueName) = editorValue 
                    Catch ex As Exception 
                        'Label1.Text = (Label1.Text + ("Unable to insert. Reason: " + ex.Message)) 
                        e.Canceled = True 
                    End Try 
                End If 
            End If 
        Next 
 
        '_customDataSet.AcceptChanges() 
 
 
        CustomTable.Rows.Add(NewRow) 
        Me.GridSource.AcceptChanges() 
        Me.ViewState("_gds") = GridSource 
 
 
        'CustomTable.AcceptChanges() 
 
    End Sub 
End Class 
 


jgill
Top achievements
Rank 1
 answered on 15 Nov 2009
3 answers
122 views
Hello,
I have a RadComboBox in the Edit Form Template. On edit, I have to load data in it, but I can't find the the control.
Anyone with the solution !!!!

Regards,

Talha Majeed
Talha
Top achievements
Rank 2
 answered on 14 Nov 2009
0 answers
161 views
Hi, is there a way to disable tab key during editmodes = design?

Thanks in advance,
RJ
RJ
Top achievements
Rank 1
 asked on 14 Nov 2009
2 answers
99 views
I'm getting a strange design-time error viewing a RADGrid in VS2008. I've attached a image of the error window. It was working fine and something I did recently caused this but I can't nail it down. What could cause this error?

Thanks,
Bob
arnaud
Top achievements
Rank 1
 answered on 14 Nov 2009
9 answers
317 views
Hi guys

I have gone though the help section how to  access rows and columns  to do this but all key returns is '&nbsp;' The table has data and is populating that column with data. Any Ideas what I am doing wrong?

 <telerik:GridBoundColumn DataField="Tariff ID" HeaderText="Tariff ID" 
                                    SortExpression="Tariff ID" UniqueName="TariffID">
                                </telerik:GridBoundColumn>
and in code
Protected Sub RadGridMain_ItemCreated(ByVal sender As Object, ByVal e As GridItemEventArgs) Handles RadGridMain.ItemCreated
If TypeOf e.Item Is GridDataItem Then
            Dim dataItem As GridDataItem = CType(e.Item, GridDataItem)
            Dim key As String = dataItem("TariffID").Text
....
....


          
Steve Napurano
Top achievements
Rank 1
 answered on 14 Nov 2009
2 answers
129 views
Ok, so I would like this panel bar to be built and use a data source but the problem is that I use 3 tables for the source.

I have

  tblCategory
-cID                    Auto
-cName              String
-cDescription     String
-isDeleted          Boolean

  tblProducts
-pID                   Auto
-pNumber          String
-pName             String
-isDeleted         Boolean

and because products can be listed under multiple categories I have an intermediate table called

  tblInfo
-iID      Integer
-cID     Integer
-pID     Integer

Now I have created a table adaptor I call Navigation which loads like ...
SELECT        c.cID, c.cName, c.cDescription, p.pID, p.pNumber, p.pName
FROM            ((tblCategories c INNER JOIN
                         tblInfo i ON c.cID = i.cID) INNER JOIN
                         tblProducts p ON i.pID = p.pID)
WHERE        (c.isDeleted = False) AND (p.isDeleted = False)
ORDER BY c.cOrder, p.pName

so I have

-cID
-cName
-cDescriptino
-pID
-pNumber
-pName

and what I would like is for all the products to be listed under the categories.  Below is a sampling output of the table.

2 Skin Cleansers d 25 311 C-Mollient Gel Cleanser
2 Skin Cleansers d 20 043 LactiCleanse Creamy
2 Skin Cleansers d 21 243 LactiCleanse Foamy
2 Skin Cleansers d 22 247 Multi HA Cleanser
2 Skin Cleansers d 19 248 NeutraCleanse
2 Skin Cleansers d 23 286 RosaCleanse Creamy
2 Skin Cleansers d 24 287 RosaCleanse Foamy
3 Anti-Photoaging Anti Photo Aging 8 270 CEGA 30+FERULIC Cream
3 Anti-Photoaging Anti Photo Aging 3 269 CEGA 30+FERULIC Serum
3 Anti-Photoaging Anti Photo Aging 4 205 CEGA Eye Area
3 Anti-Photoaging Anti Photo Aging 32 206 C-Mollient Serum
3 Anti-Photoaging Anti Photo Aging 27 212 C-mollient

But when I try to specify 2 as the parent and pID as the child it gives me errors..

[ArgumentException: These columns don't currently have unique values.]

any help would be greatly appreciated.



Robert Gouin
Top achievements
Rank 1
 answered on 14 Nov 2009
3 answers
276 views
I'm using a RADGrid, with AllowFilteringByColumn set to true, and am setting the DataSource property in my page's OnLoad handler in code-behind. I don't call DataBind(). When I enter something in a filter field and choose 'Contains' (or anything) from the list of filter types, the page reloads but is completely blank. What am I doing wrong?

Thanks,
 Bob
Bob Uva
Top achievements
Rank 1
 answered on 13 Nov 2009
2 answers
114 views
If a user adds a word to the dictionary in the rad editor how can that action be undone or how can the word be removed from the dictionary? In MS Word when a user chooses "add to dictionary" in order to undo the "add" i.e. take it out of the dictionary, the user can edit a list of words added to the dictionary with an option to remove a word. Is that possible here ? or is there way to edit words added to the dictionary in the editor i.e. push a button and a list appears with an option to to remove from a list of word added to the dictionary. Let me know Thanks in advance.
Ken Gunderman
Top achievements
Rank 1
 answered on 13 Nov 2009
0 answers
32 views
Hello wonderful Telerik community!

1. Does anyone have a solution to search for string in different file types such as PDF, Word, Excel, Powerpoint, Text files or others?
2. Is it possible to search a file that is being pointed to by a Hyperlink?

Thanks for any feedback.
Virgil Rodriguez
Top achievements
Rank 1
 asked on 13 Nov 2009
3 answers
202 views
Hello,
   I need to wrap RadScheduler into a custom control.  We need to customize the Advanced Edit form.  How can I implement AdvancedEditTemplate and add ASCX advanced form dynamically?  Does anyone have an example how to do that?
Thanks in advance,
Nick
Nick S
Top achievements
Rank 1
 answered on 13 Nov 2009
Narrow your results
Selected tags
Tags
+? more
Top users last month
Simon
Top achievements
Rank 2
Iron
Iron
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Marco
Top achievements
Rank 4
Iron
Iron
Iron
Grant
Top achievements
Rank 3
Iron
Iron
Iron
Kao Hung
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Simon
Top achievements
Rank 2
Iron
Iron
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Marco
Top achievements
Rank 4
Iron
Iron
Iron
Grant
Top achievements
Rank 3
Iron
Iron
Iron
Kao Hung
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?