Many Grid Questions

6 posts, 0 answers
  1. bslaght
    bslaght avatar
    184 posts
    Member since:
    Jun 2006

    Posted 13 Jun 2008 Link to this post

    I am using the Grid to get data reported back to me  I need to accomplish the following tasks.  I will ayout my issues, please feel to help with any or all of them.

    1. Can add multiple records at a time.  If so how?  What I envision, is the the grid loads, you click add new record, fill out the in-line form, click Add New record, and a new row is appended in edit mode still, tehn at teh end a sdingle postback sends all rows to the database.

    2. How can I set a GridDateTimeColumn editor to "Today's Date"

    3. How can I set a GridDropDownColumn editor to not wrap the options in the drop down list

    4.How can I "pre-populate"  a field with the current UserID when the grid is set in "edit" or "Add new record" mode.  I envision something like this:

    Dim UserID As String  
    If RadGrid1.CurrentMode = RadGridMode.Insert Then  
    UserID = Membership.GetUser.UserName.ToString()  
    CType(Me.RadGrid1.FindControl("UserIDTextbox"), Text).Text = UserID 
    End If 

    5. How do I make the value of a field be the default for subsequent added records.  For example, one column contains population.  So after the first row as been added I would like the column to default to the initial value entered in the population field during the same session.

    Any help would be great thanks,
    Brett
  2. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 16 Jun 2008 Link to this post

    Hi Bslaght,

    1. You can find attached a sample project demonstrating the functionality you requested. InsertCommand places the inserted data into a hashtable and stores in the Session, whereas we have a UpdateAll button in the command item which retrieves the hashtables from the session and you can manually insert them in the data source.

    2. For getting the current date in the DateTime editor, you can do the following:

    void RadGrid1_InsertCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) 
        GridEditableItem item = (GridEditableItem)e.Item; 
        (item.EditManager.GetColumnEditor("ColumnUniqueName"as GridDateTimeColumnEditor).Text = System.DateTime.Today.ToString(); 

    3. To force a GridDropDownListColumnEditor not to wrap, you can set its DropDownStyle.Width to a custom unit in the ItemDataBound event handler:

    (item.EditManager.GetColumnEditor("Category"as GridDropDownListColumnEditor).DropDownStyle.Width = Unit.Pixel(80); 


    4. To set an initial value to a field in insert mode, you can do the following:

    void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
        { 
            if (e.Item is GridEditFormInsertItem) 
            { 
                GridEditFormInsertItem item = (GridEditFormInsertItem)e.Item; 
                (item.EditManager.GetColumnEditor("ProductID"as GridTextBoxColumnEditor).Text = "102"
            } 
        } 

    In the ItemDataBound the EditFormInsertItem is referenced and its respective column editor is set. This is also demonstrated in the attached sample project.

    5. This question is closely related to the previous one. Again in the ItemDataBound event you can set values for any of the column editors you have in your grid. You can also store values in the session and place them in the editors.

    Greetings,
    Veli
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. bslaght
    bslaght avatar
    184 posts
    Member since:
    Jun 2006

    Posted 24 Jun 2008 Link to this post

    Hi Veli,
      I have been trying to get some of the code to work but without much luck.  Ihave been using code converter to move it over to VB, but am getting some syntax errors.

    Current DateTime: Syntax Error - Line 3
    1 Sub RadGrid1_InsertCommand(ByVal source As ObjectByVal e As Telerik.Web.UI.GridCommandEventArgs)  
    2     Dim item As GridEditableItem = DirectCast(e.Item, GridEditableItem)  
    3     (TryCast(item.EditManager.GetColumnEditor("ColumnUniqueName"), GridDateTimeColumnEditor)).Text = System.DateTime.Today.ToString()  
    4 End Sub 

    NoWrap Drop Down Values: Syntax Error - Line 2
    1 Protected Sub RadGrid1_ItemDataBound(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound  
    2         (TryCast(item.EditManager.GetColumnEditor("CauseID"), GridDropDownListColumnEditor)).DropDownStyle.Width = Unit.Pixel(80)  
    3     End Sub 

    Seting Default Values: Syntax Error - Line 4
    1  Sub RadGrid1_ItemDataBound(ByVal sender As ObjectByVal e As GridItemEventArgs)  
    2         If TypeOf e.Item Is GridEditFormInsertItem Then 
    3             Dim item As GridEditFormInsertItem = DirectCast(e.Item, GridEditFormInsertItem)  
    4         (TryCast(item.EditManager.GetColumnEditor("ProductID"), GridTextBoxColumnEditor)).Text = "102" 
    5         End If 
    6     End Sub 


    What is teh proper VB method of achiving these tasks?

    Thanks again,
    Brett
  5. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 24 Jun 2008 Link to this post

    Hi bslaght,

    Try the following:

    Private Sub RadGrid1_InsertCommand(ByVal source As System.ObjectByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.InsertCommand 
            Dim item As GridEditableItem = DirectCast(e.Item, GridEditableItem) 
            Dim Editor = CType(item.EditManager.GetColumnEditor("ColumnUniqueName"), GridDateTimeColumnEditor) 
            Editor.Text = System.DateTime.Today.ToString() 
        End Sub 

    And also:

    Protected Sub RadGrid1_ItemDataBound(ByVal source As ObjectByVal e As GridItemEventArgs) Handles RadGrid1.ItemDataBound 
            If TypeOf e.Item Is GridEditFormInsertItem Then 
                Dim item = CType(e.Item, GridEditFormInsertItem) 
                Dim editor = CType(item.EditManager.GetColumnEditor("ProductID"), GridTextBoxColumnEditor) 
                editor.Text = "102" 
            End If 
        End Sub 


    Kind regards,
    Veli
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  6. bslaght
    bslaght avatar
    184 posts
    Member since:
    Jun 2006

    Posted 08 Jul 2008 Link to this post

    Hi Guys,
     I am sorry to say I am still not havng much luck with examples you have given.  I think I am going to forget about the multiple new records for now and just try and get the features workng.

    I have posted my code for vb and aspx, please review and let me know where I have gone wrong.

    None of the pre-populated fields are working (UserID/ReportDate) and my dropdown column still is wrapping the text.

    Thanks for any insight you can provide.

    VB.net

    1  Protected Sub RadGrid1_InsertCommand(ByVal source As System.ObjectByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.InsertCommand  
    2         Dim item As GridEditableItem = DirectCast(e.Item, GridEditableItem)  
    3         Dim Editor = CType(item.EditManager.GetColumnEditor("ReportDate"), GridDateTimeColumnEditor)  
    4         Editor.Text = System.DateTime.Today.ToString()  
    5     End Sub 
    6     Protected Sub RadGrid1_ItemDataBound(ByVal source As ObjectByVal e As GridItemEventArgs) Handles RadGrid1.ItemDataBound  
    7         If TypeOf e.Item Is GridEditFormInsertItem Then 
    8             Dim item = CType(e.Item, GridEditFormInsertItem)  
    9             Dim editor = CType(item.EditManager.GetColumnEditor("UserID"), GridTextBoxColumnEditor)  
    10             'editor.Text = Membership.GetUser.UserName.ToString()  
    11             editor.Text = "102" 
    12             CType(item.EditManager.GetColumnEditor("CauseID"), GridDropDownListColumnEditor).DropDownStyle.Width = Unit.Pixel(80)  
    13         End If 
    14     End Sub 

    aspx

    <

    telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="dsSchoolReports"

    Skin="WebBlue" GridLines="None" Width="95%" AutoGenerateDeleteColumn="True"

    AutoGenerateEditColumn="True" OnItemDataBound="RadGrid1_ItemDataBound" OnInsertCommand="RadGrid1_InsertCommand">

    <

    MasterTableView autogeneratecolumns="False" datakeynames="id"

    datasourceid="dsSchoolReports" AllowAutomaticDeletes="True"

    AllowAutomaticInserts="True" AllowAutomaticUpdates="True"

    CommandItemDisplay="Bottom" EditMode="InPlace">

    <

    RowIndicatorColumn Visible="False">

    <

    HeaderStyle Width="20px"></HeaderStyle>

    </

    RowIndicatorColumn>

    <

    ExpandCollapseColumn Visible="False" Resizable="False">

    <

    HeaderStyle Width="20px"></HeaderStyle>

    </

    ExpandCollapseColumn>

    <Columns>

    <telerik:GridBoundColumn DataField="id" DataType="System.Int32" HeaderText="id"

    ReadOnly="True" SortExpression="id" UniqueName="id" Visible="False">

    </telerik:GridBoundColumn>

    <telerik:GridBoundColumn DataField="SchoolID" DataType="System.Int32"

    HeaderText="SchoolID" SortExpression="SchoolID" UniqueName="SchoolID">

    </telerik:GridBoundColumn>

    <telerik:GridDateTimeColumn DataField="ReportDate" DataType="System.DateTime"

    HeaderText="ReportDate" SortExpression="ReportDate"

    UniqueName="ReportDate"

    PickerType="DatePicker"

    ColumnEditorID="ReportDate">

    </telerik:GridDateTimeColumn>

    <telerik:GridBoundColumn DataField="UserID" DataType="System.Int32"

    HeaderText="UserID" SortExpression="UserID" UniqueName="UserID"

    ColumnEditorID="UserID">

    </telerik:GridBoundColumn>

    <telerik:GridBoundColumn DataField="StudentsAbsent" DataType="System.Int32"

    HeaderText="# Absent" SortExpression="StudentsAbsent"

    UniqueName="StudentsAbsent" MaxLength="4">

    <HeaderStyle Width="100px" />

    <ItemStyle Width="50px" />

    </telerik:GridBoundColumn>

    <%

    -- <telerik:GridBoundColumn DataField="CauseID" DataType="System.Int32"

    HeaderText="Cause of Absence" SortExpression="CauseID"

    UniqueName="CauseID">

    </telerik:GridBoundColumn>

    <telerik:GridDropDownColumn DataField="CauseID" DataType="System.Int32"

    HeaderText="Cause of Absence" SortExpression="CauseID"

    UniqueName="CauseID">

    </telerik:GridDropDownColumn>--

    %>

    <telerik:GridDropDownColumn

    UniqueName="CauseID"

    ListTextField="CauseName"

    ListValueField="id"

    DataSourceID="dsCauses"

    HeaderText="Cause of Absence"

    DataField="CauseID"

    DropDownControlType="RadComboBox"

    AllowSorting="true"

    ColumnEditorID="CauseID">

    <ItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False"

    Font-Strikeout="False" Font-Underline="False" Wrap="False" />

    </

    telerik:GridDropDownColumn>

    <telerik:GridBoundColumn DataField="SchoolPopulation" DataType="System.Int32"

    HeaderText="School Population" SortExpression="SchoolPopulation"

    UniqueName="SchoolPopulation">

    </telerik:GridBoundColumn>

    </Columns>

    <

    EditFormSettings>

    <

    PopUpSettings ScrollBars="None"></PopUpSettings>

    </

    EditFormSettings>

    </

    MasterTableView>

    </telerik:RadGrid>



    Brett
  7. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 09 Jul 2008 Link to this post

    Hello bslaght,

    The sample code you provided seems fine. I wonder why it does not work at your site. If the problem persists, please consider opening a regular support ticket where  you can provide us a sample runnable project, so that we can look into the matter and advise you further.

    Regards,
    Veli
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017