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

Databinding to data grid

3 Answers 83 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sandy
Top achievements
Rank 1
Sandy asked on 23 Aug 2012, 01:57 PM
Hi All,

I am using asp.net 2.0. 

How to populate the data from the controls to a rad grid without saving to database by clicking the add button. And later i want to add the values to database by clicking the save button.

Can any body help me out for this.

Regards,
Sandy
  

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 24 Aug 2012, 05:44 AM
Hi Sandy,

Here is a sample code snippet to populate data from a TextBox control in RadGrid on clicking 'AddNewRecord' button.

C#:
protected void Radgrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted)
    {
        string ValueToRadgrid = txtbox1.Text; // Getting the TextBox value outside the RadGrid
        GridEditFormInsertItem editInsert = (GridEditFormInsertItem)e.Item;
        TextBox txt = (TextBox)editInsert["UniqueName"].Controls[0];
        txt.Text = ValueToRadgrid;
    }
}

Thanks,
Princy.
0
Sandy
Top achievements
Rank 1
answered on 24 Aug 2012, 10:22 AM
Hi princy,

Can you send me the code in vb please and i am using 2 rad combo. by clicking on add button i want to add the values of the two combo to rad grid.

I have to fire the event in add button click event.

thanks in advance
0
Princy
Top achievements
Rank 2
answered on 27 Aug 2012, 09:32 AM
Hi Sandy,

Please take a look into the following code snippet to give RadComboBox selected value in the RadGrid when clicking the AddNewRecord Button.

VB:
Protected Sub Radgrid1_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs)
    If TypeOf e.Item Is GridEditFormInsertItem AndAlso e.Item.OwnerTableView.IsItemInserted Then
        Dim ValueToRadgrid1 As String = RadComboBox1.SelectedValue
        Dim ValueToRadgrid2 As String = RadComboBox2.SelectedValue
        Dim editInsert As GridEditFormInsertItem = DirectCast(e.Item, GridEditFormInsertItem)
        Dim txt As TextBox = DirectCast(editInsert("UniqueName1").Controls(0), TextBox)
        txt.Text = ValueToRadgrid1
        Dim txt1 As TextBox = DirectCast(editInsert("UniqueName2").Controls(0), TextBox)
        txt1.Text = ValueToRadgrid2
    End If
End Sub

Thanks,
Princy.
Tags
Grid
Asked by
Sandy
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Sandy
Top achievements
Rank 1
Share this question
or