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

[Solved] How to Prevent "DataBinder.Eval" to Creating Duplicate Records?

1 Answer 136 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Eric
Top achievements
Rank 1
Eric asked on 22 May 2009, 02:53 PM

Please find below, code snippets from my RadGrid. The grid has a column which is editable using a drop down RadComboBox. The basic idea is to select a new technician (ASSIGNED_TO) from the drop down RadComboBox list and insert the new record in a different table.

On the server side, the insert command is working just fine. I can stop the debugger and verify the records in the database. But on the client side,  <%#DataBinder.Eval(Container.DataItem,"ASSIGNED_TO")%> is updating all similar record in the table with the new technician name (ASSIGNED_TO), creating duplicates.

How can I prevent that from happening? Is there a property that can be enabled/disabled?

(1) SERVER SIDE INSERT STATEMENT

                sqlConnection.Open();

                string insertQuery = "INSERT INTO [AssistTech] (" +
                                                               "[PARENT_CHANGE], " +
                                                               "[NUMBERPRGN], " +
                                                               "[ASSIGNED_DEPT], " +
                                                               "[ASSIGNED_TO], " +
                                                               "[CATEGORY], " +
                                                               "[LOCATION], " +
                                                               "[PLANNED_START], " +
                                                               "[PLANNED_END], " +
                                                               "[SLA_START], " +
                                                               "[SLA_DEADLINE], " +
                                                               "[STATUS], " +
                                                               "[ROLE]) VALUES (" +
                                                                ticket + "," +
                                                                task + ",'" +
                                                                department + "','" +
                                                                technician + "','" +
                                                                category + "','" +
                                                                location + "','" +
                                                                startDate + "','" +
                                                                endDate + "','" +
                                                                slaStartDate + "','" +
                                                                slaDeadline + "','" +
                                                                status + "','" +
                                                                role + "')";

 

 

(2) CLIENT SIDE CODE
<telerik:GridTemplateColumn UniqueName="TemplateColumn" HeaderText="Assist" SortExpression="ASSIGNED_TO"
                                CurrentFilterFunction="Contains">
                                <ItemTemplate>
                                    <%#DataBinder.Eval(Container.DataItem, "ASSIGNED_TO")%>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <telerik:RadComboBox runat="server" ID="RadComboBox1" DataTextField="ASSIGNED_TO"
                                        DataValueField="ASSIGNED_TO" EnableLoadOnDemand="True" EnableItemCaching="True"
                                        OnItemsRequested="RadComboBox1_ItemsRequested" Height="140px" SelectedValue='<%#Bind("ASSIGNED_TO") %>'
                                        DataSourceID="SqlDataSource5" AppendDataBoundItems="False" Sort="Ascending">
                                    </telerik:RadComboBox>
                                </EditItemTemplate>
                            </telerik:GridTemplateColumn>    



Thanks,
Baxis

1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 26 May 2009, 02:03 PM
Hello Eric,

To attain the required functionality you need to filter the provided data before bind the grid with it. You cannot use DataBinder.Eval() to prevent duplicated rows. You can use the DISTINCT Sql clause to return only unique records and bind grid with them.

Let me know if I am missing something in your logic.

Best regards,
Georgi Krustev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Eric
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or