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

Grid, using Dataset with Insert/Update/Delete Issues

3 Answers 114 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 12 Aug 2011, 07:32 PM
Hello All,

I am recently working on a problem where i need to create an area for customer to entering employees information, to start off there will be no information contained within the table. Then using the setup down below and some back end C# i want to populate the GridEditForm that also doesn't want to popup. I have been looking for some information on how to program in the back end or possibly java script, though i don't see this as a client side issue. this as i wish i could use an sql data source but to limit access and security we use web services where i get information in a data set which i want to manipulate then send it only once it has been completed.

There's pretty much no C# back end as of now, just a garbled mess of failed tests

ASP
<telerik:RadGrid ID="grdEmployee" GridLines="Horizontal" runat="server" AllowAutomaticDeletes="True"
                        AllowAutomaticInserts="True" PageSize="25" AllowAutomaticUpdates="True" AllowPaging="True"
                        AutoGenerateColumns="False" OnItemUpdated="grdEmployee_ItemUpdated" OnItemDeleted="grdEmployee_ItemDeleted"
                        OnItemInserted="grdEmployee_ItemInserted" OnItemCreated="grdEmployee_ItemCreated"
                        OnEditCommand="grdEmployee_OnEdit" OnNeedDataSource="grdEmployee_OnNeedDataSource">
                      
                        <PagerStyle Mode="NextPrevAndNumeric" />
                         
                        <MasterTableView Width="100%" CommandItemDisplay="Top" AutoGenerateColumns="False"
                            ShowHeadersWhenNoRecords="true">
                            <Columns>
                                <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="editColumn">
                                    <ItemStyle CssClass="btnEdit" />
                                </telerik:GridEditCommandColumn>
                                <telerik:GridDropDownColumn DataField="Employee" HeaderText="Employee" ListTextField="listEmployeeName"
                                    ListValueField="EmployeeName" UniqueName="EmployeeName" ColumnEditorID="grdEmployeeDDLEditor">
                                </telerik:GridDropDownColumn>
                                <telerik:GridMaskedColumn HeaderText="Last 4 SSN" Mask="####" AllowSorting="false"
                                    UniqueName="DetailSSN" ColumnEditorID="">
                                </telerik:GridMaskedColumn>
                                <telerik:GridDropDownColumn DataField="CraftDescription" HeaderText="Craft" ListTextField="listEmployeeCraft"
                                    ListValueField="EmployeeCraft" UniqueName="EmployeeCraft" ColumnEditorID="grdEmployeeDDLEditor">
                                </telerik:GridDropDownColumn>
                                <telerik:GridDropDownColumn DataField="JobClassDescription" HeaderText="Job Level"
                                    ListTextField="listEmployeeLevel" ListValueField="EmployeeLevel" UniqueName="EmployeeLevel"
                                    ColumnEditorID="grdEmployeeDDLEditor" EditFormColumnIndex="1">
                                </telerik:GridDropDownColumn>
                                <telerik:GridNumericColumn DataField="HoursWorked" HeaderText="Hours Worked" UniqueName="EmployeeHoursWorked"
                                    NumericType="Number" AllowRounding="false" DecimalDigits="2" ColumnEditorID="grdEmployeeNumericColoumnEditor"
                                    EditFormColumnIndex="1">
                                </telerik:GridNumericColumn>
                                <telerik:GridNumericColumn DataField="RateOfPay" HeaderText="Rate of Pay with Benefits"
                                    UniqueName="EmployeeRateOfPay" NumericType="Currency" AllowRounding="false" DecimalDigits="2"
                                    ColumnEditorID="grdEmployeeNumericColoumnEditor" EditFormColumnIndex="1">
                                </telerik:GridNumericColumn>
                                <telerik:GridButtonColumn ConfirmText="Delete this Payroll Entry?" ConfirmDialogType="RadWindow"
                                    ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" Text="Delete"
                                    UniqueName="DeleteColumn">
                                    <ItemStyle HorizontalAlign="Center" CssClass="btnEdit" />
                                </telerik:GridButtonColumn>
                            </Columns>
                            <CommandItemSettings ShowRefreshButton="false"  />
                            <EditFormSettings ColumnNumber="2" CaptionDataField="EmployeeName" CaptionFormatString="Edit Payroll Entry for {0}"
                                InsertCaption="New Payroll Entry">
                                <FormTableItemStyle Wrap="False"></FormTableItemStyle>
                                <FormCaptionStyle CssClass="grdEditForm"></FormCaptionStyle>
                                <FormMainTableStyle GridLines="None" CellSpacing="0" CellPadding="3" BackColor="White"
                                    Width="100%" />
                                <FormTableStyle CellSpacing="0" CellPadding="2" Height="110px" BackColor="White" />
                                <FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle>
                                <EditColumn ButtonType="ImageButton" InsertText="Add Entry" UpdateText="Update Entry"
                                    UniqueName="EditCommandColumn1" CancelText="Cancel Edit">
                                </EditColumn>
                                <FormTableButtonRowStyle HorizontalAlign="Right"></FormTableButtonRowStyle>
                            </EditFormSettings>
                        </MasterTableView>
                        <ClientSettings>
                            <ClientEvents OnRowDblClick="grdEmployee_RowDblClick" />
                        </ClientSettings>
                    </telerik:RadGrid>
                    <telerik:GridDropDownListColumnEditor ID="grdEmployeeDDLEditor" runat="server" DropDownStyle-Width="110px" />
                    <telerik:GridNumericColumnEditor ID="grdEmployeeNumericColoumnEditor" runat="server"
                        NumericTextBox-Width="125px" />
                    <telerik:RadWindowManager ID="RadWindowManager1" runat="server">
                    </telerik:RadWindowManager>

And for posterity a brief snippet of C# of my data set

C#
protected void createDummyRow()
    {
        employeeDummyRow = new DataSet();
        DataTable dummyTable = employeeDummyRow.Tables.Add();
 
        dummyTable.Columns.Add("Employee", typeof(String));
        dummyTable.Columns.Add("CraftDescription", typeof(String));
        dummyTable.Columns.Add("JobClassDescription", typeof(String));
        dummyTable.Columns.Add("HoursWorked", typeof(Decimal));
        dummyTable.Columns.Add("RateOfPay", typeof(Decimal));
 
        dummyTable.Rows.Add("","","",1,1);
    }
 
    protected void Page_UnLoad(object sender, EventArgs e)
    {
        if (dsEmployees == null)
        {
            Session["dsEmployees"] = grdEmployee.DataSource;
        }
        else
        {
            Session["dsEmployees"] = dsLEAPEmployees;
        }
 
    }
 
    public void grdEmployee_OnNeedDataSource(Object sender, EventArgs e)
    {
        if (grdEmployee.DataSourceIsAssigned == true)
        {
            grdEmployee.DataSource = grdEmployee.DataSource;
        }
        else
        {
            grdEmployee.DataSource = employeeDummyRow.Tables[0].DefaultView;
        }
         
    }

I hope someone can suggest possibly a mind blowingly easy way to merge data set and caching of the data with the current structure!

Thanks!

David

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 18 Aug 2011, 10:21 AM
Hello David,

This approach won't work with automatic operations - you will have to delete/update/insert items from/to your DataSet manually.
Updating Values Using InPlace and EditForms Modes
Inserting Values Using InPlace and EditForms Modes
Deleting Records

It is ok to create an empty datasource that is saved to the Session state, but your code seems overly complicated to me. This should be enough:
protected DataTable GenerateEmptyDataSource()
{
    DataTable dummyTable = new DataTable();
 
    dummyTable.Columns.Add("Employee", typeof(String));
    dummyTable.Columns.Add("CraftDescription", typeof(String));
    dummyTable.Columns.Add("JobClassDescription", typeof(String));
    dummyTable.Columns.Add("HoursWorked", typeof(Decimal));
    dummyTable.Columns.Add("RateOfPay", typeof(Decimal));
 
    dummyTable.Rows.Add("", "", "", 1, 1);
 
    return dummyTable;
}
 
public void grdEmployee_OnNeedDataSource(Object sender, EventArgs e)
{
    if (Session["dsEmployees"] == null)
        Session["dsEmployees"] = GenerateEmptyDataSource();
    grdEmployee.DataSource = (DataTable)Session["dsEmployees"];
}

It would be even better to expose the Session["dsEmployees"] via property:
public DataTable DsEmployees
{
    get
    {
        if (Session["dsEmployees"] == null)
            Session["dsEmployees"] = GenerateEmptyDataSource();
        return (DataTable)Session["dsEmployees"];
    }
    set { Session["dsEmployees"] = value; }
}

In order to show the edit from in a popup you have to set the EditMode property to PopUp
PopUp Edit Form help topic

<MasterTableView ... EditMode="PopUp" ...

Merging DataSets could be implemented using the Merge method as explained in MSDN:
DataSet.Merge Method

Best regards,
Daniel
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Kholisa
Top achievements
Rank 1
answered on 07 Jun 2012, 02:33 PM
Hi Daniel

I got a radGrid I update on it but now i dont want to update all my fields meaning i want a user to be restricted on accessing some textboxes during update on the grid.My problem is when i make them readonly they overwrite on database as null not keeping thier records. how would i achieve that?
0
Daniel
Telerik team
answered on 12 Jun 2012, 01:50 PM
Hello Kholisa,

May I know what is your scenario? Is it similar to the one described by the thread starter?
It would be helpful if you can post some code outlining your approach.

Regards,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
David
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Kholisa
Top achievements
Rank 1
Share this question
or