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

How could i Add row in server side coding

1 Answer 41 Views
UI for ASP.NET AJAX in ASP.NET MVC
This is a migrated thread and some comments may be shown as answers.
Tamim
Top achievements
Rank 1
Tamim asked on 23 Apr 2013, 04:45 AM
Hi,
  I have using RadGrid. In default row set in 5. Assign the more than 5 rows how could i add row

This is my coding its working good but greater then 4 row empty row added previous row value clear.

using (var db = new DoskContractServicesDataContext(Globals.strCon))
            {
                var ClaimAssign = (from a in db.DSProjectMasters
                                   where !db.ProjectSubCons.Any(b => b.ProjectCode == a.ProjectCode && b.status != "DEL" && b.compcode == a.CompCode && b.Subconcode==Subcontractor.SelectedValue) && a.CompCode == compcode && a.FinalStatus == "Cls" && a.Status != "DEL"
                                   select new { a.ProjectCode, a.ProjectTitle,a.DtCommencement,a.DtCompletion,a.ContractAmount }).ToList();
                for (int i = 0; i <= RadGrid1.MasterTableView.Items.Count - 1; i++)
                {
                    Label SNO = (Label)RadGrid1.MasterTableView.Items[i].FindControl("Sno");
                    RadTextBox ProjectID = (RadTextBox)RadGrid1.MasterTableView.Items[i].FindControl("ProjectID");
                    RadTextBox ProjectTitle = (RadTextBox)RadGrid1.MasterTableView.Items[i].FindControl("ProjectTitle");
                    Label claimnostart = (Label)RadGrid1.MasterTableView.Items[i].FindControl("claimnostart");
                    RadDatePicker RadDatePicker1 = (RadDatePicker)RadGrid1.MasterTableView.Items[i].FindControl("Mainprojectcommencement");
                    RadDatePicker RadDatePicker2 = (RadDatePicker)RadGrid1.MasterTableView.Items[i].FindControl("MainprojectCompletion");
                    HiddenField MainContractAmount = (HiddenField)RadGrid1.MasterTableView.Items[i].FindControl("MainContractAmount");

                    if (ClaimAssign.Count() > i)
                    {
                        SNO.Text = Convert.ToString(i + 1);
                        ProjectID.Text = ClaimAssign[i].ProjectCode.ToString();
                        ProjectTitle.Text = ClaimAssign[i].ProjectTitle.ToString();
                        RadDatePicker1.SelectedDate = ClaimAssign[i].DtCommencement;
                        RadDatePicker2.SelectedDate = ClaimAssign[i].DtCompletion;
                        MainContractAmount.Value = ClaimAssign[i].ContractAmount.ToString();
                        claimnostart.Text = ClaimAssign[i].ProjectCode.ToString() + "/" + compcode + "/" + "PCL";
                        if (i >= 4)
                            addrow(i);
                    }
                }
            }

 private void addrow(int currow)
        {
            object[] emptyRow = new object[columcount];
            tabledata1 = null;
            DataTable dt = tabledata1;
            assigndt2(dt);
            dt.Rows.Add(emptyRow);
            RadGrid1.DataSource = dt;
            RadGrid1.DataBind();
        }

private void assigndt2(DataTable dt)
        {
            RadTextBox r1;
            RadNumericTextBox rn1;
            CheckBox c1;
            Label l1;
            HiddenField h1;
            RadDatePicker d1;

            for (int i = 0; i <= RadGrid1.Items.Count - 1; i++)
            {
                if (dt.Rows.Count - 1 < i)
                {
                    object[] emptyRow = new object[columcount];
                    dt.Rows.Add(emptyRow);
                }
                //c1 = (CheckBox)RadGrid1.Items[i].FindControl("active");
                //dt.Rows[i]["active"] = c1.Text;
                l1 = (Label)RadGrid1.Items[i].FindControl("Sno");
                dt.Rows[i]["Sno"] = l1.Text;
                r1 = (RadTextBox)RadGrid1.Items[i].FindControl("ProjectID");
                dt.Rows[i]["ProjectID"] = r1.Text;
                r1 = (RadTextBox)RadGrid1.Items[i].FindControl("ProjectTitle");
                dt.Rows[i]["ProjectTitle"] = r1.Text;
                r1 = (RadTextBox)RadGrid1.Items[i].FindControl("Subcontitle");
                dt.Rows[i]["Subcontitle"] = r1.Text;
                d1 = (RadDatePicker)RadGrid1.Items[i].FindControl("DateofCommencement");
                dt.Rows[i]["DateofCommencement"] = d1.SelectedDate;
                d1 = (RadDatePicker)RadGrid1.Items[i].FindControl("Mainprojectcommencement");
                dt.Rows[i]["Mainprojectcommencement"] = d1.SelectedDate;
                d1 = (RadDatePicker)RadGrid1.Items[i].FindControl("DateofCompletion");
                dt.Rows[i]["DateofCompletion"] = d1.SelectedDate;
                d1 = (RadDatePicker)RadGrid1.Items[i].FindControl("MainprojectCompletion");
                dt.Rows[i]["MainprojectCompletion"] = d1.SelectedDate;
                rn1 = (RadNumericTextBox)RadGrid1.Items[i].FindControl("ContractAmount");
                dt.Rows[i]["ContractAmount"] = rn1.Text;
                h1 = (HiddenField)RadGrid1.Items[i].FindControl("MainContractAmount");
                dt.Rows[i]["MainContractAmount"] = h1.Value;
                rn1 = (RadNumericTextBox)RadGrid1.Items[i].FindControl("LD");
                dt.Rows[i]["LD"] = rn1.Text;
                d1 = (RadDatePicker)RadGrid1.Items[i].FindControl("tentativedate");
                dt.Rows[i]["tentativedate"] = d1.SelectedDate;
                l1 = (Label)RadGrid1.Items[i].FindControl("claimnostart");
                dt.Rows[i]["claimnostart"] = l1.Text;
                rn1 = (RadNumericTextBox)RadGrid1.Items[i].FindControl("autoclaimno");
                dt.Rows[i]["autoclaimno"] = rn1.Text;
                rn1 = (RadNumericTextBox)RadGrid1.Items[i].FindControl("paymentcert");
                dt.Rows[i]["paymentcert"] = rn1.Text;
            }
        }


Thanks & Advance
Ansari.

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 26 Apr 2013, 08:12 AM
Hi Ansari,

Please note that using DataBind() is not recommended. Performing complex grid operations such as Inserting, Deleting, Updating, Hierarchy relations, grouping, Paging, Sorting, Filtering require accommodating appropriate database operations.  Therefore, we suggest you to avoid Simple Databinding and strongly recommend the use of more advanced databinding methods, which automatically handle the aforementioned functions:
Declarative DataSource
Advanced Data Binding

Hope this helps. Please give it a try and let me know about the result.

Regards,
Eyup
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
UI for ASP.NET AJAX in ASP.NET MVC
Asked by
Tamim
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or