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

How could i data not clear using button click

2 Answers 57 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 17 Oct 2012, 09:33 AM
I have used two Rad Tab in my form
1st tab added some text field
2nd tab added Rad Grid. see my screen shot
Default row 5 is set then i have add row using addrow button to click.
When i click Add Row button to row create but previous row clear

This is my addrow coding:
private void addrow(int currow)//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)
        {
            RadComboBox r1;
            RadNumericTextBox rn1;

            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);
                }
                r1 = (RadComboBox)this.RadGrid1.Items[i].FindControl("Workdesc");
                dt.Rows[i]["Workdesc"] = r1.Text;
                r1 = (RadComboBox)this.RadGrid1.Items[i].FindControl("Radcombo_Unit");
                dt.Rows[i]["Radcombo_Unit"] = r1.Text;
                rn1 = (RadNumericTextBox)this.RadGrid1.Items[i].FindControl("Quantity");
                dt.Rows[i]["Quantity"] = rn1.Text;
                rn1 = (RadNumericTextBox)this.RadGrid1.Items[i].FindControl("Rate");
                dt.Rows[i]["Rate"] = rn1.Text;
                rn1 = (RadNumericTextBox)this.RadGrid1.Items[i].FindControl("Amount");
                dt.Rows[i]["Amount"] = rn1.Text;
                rn1 = (RadNumericTextBox)this.RadGrid1.Items[i].FindControl("Fees");
                dt.Rows[i]["Fees"] = rn1.Text;
                rn1 = (RadNumericTextBox)this.RadGrid1.Items[i].FindControl("Total");
                dt.Rows[i]["Total"] = rn1.Text;


            }

        }

2 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 19 Oct 2012, 10:46 AM
Hello Ansari,

I am not sure how you are bindng your grid but you do need to use Advanced data-binding for it as opposed to simple data-binding. Then, you should call the grid's Rebind() method, not DataBind() when adding the new record. Now, when you click the Add Row button you should take the last item in the Grid or whatever index it has (the grid items are kept in the RadGrid1.Items collection), cast it to a GridDataItem object and as you have done, traverse the controls in each column and get the value of the corresponding field. Now that you have all the field values, construct a new DataRow, insert in the data table at the right place and call the grid's Rebind() method. Do note that the data table should be assigned to the grid's DataSource property only in the NeedDataSource event, so you should rework your data-binding logic accordingly.

Regards, Tsvetoslav
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.
0
Tamim
Top achievements
Rank 1
answered on 22 Oct 2012, 09:05 AM
Thanks for ur reply Tsvetoslav


Thanks,
Ansari.
Tags
UI for ASP.NET AJAX in ASP.NET MVC
Asked by
Tamim
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Tamim
Top achievements
Rank 1
Share this question
or