How could i data not clear using button click

Thread is closed for posting
3 posts, 0 answers
  1. Tamim
    Tamim avatar
    64 posts
    Member since:
    May 2011

    Posted 17 Oct 2012 Link to this post

    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;
                RadGrid1.DataSource = dt;

    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];
                    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. Tsvetoslav
    Tsvetoslav avatar
    1823 posts

    Posted 19 Oct 2012 Link to this post

    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.
  3. Tamim
    Tamim avatar
    64 posts
    Member since:
    May 2011

    Posted 22 Oct 2012 Link to this post

    Thanks for ur reply Tsvetoslav

Back to Top