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

How do I access the insert textbox programmatically when you click Add New Record

4 Answers 94 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 16 Jun 2010, 01:36 PM

I have to set the insert paramaters through the InsertCommand Event of the radgrid and need to get the value of the texbox that shows after you click "Add New Record".  How do I get the value from the textbox?

4 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 16 Jun 2010, 01:44 PM
Hello Richard,

Please examine the following links:

[EditForms / InPlace ]
Inserting values in-place and EditForms

[UserControl / FormTemplate]
Inserting values using UserControl/FormTemplate

Best regards,
Daniel
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Richard
Top achievements
Rank 1
answered on 16 Jun 2010, 03:05 PM
Thank you for the links to the examples.  They are helpful but a little over my head with the knowledge I have right now.

If you view the attached jpg, you will see what I am trying to do.  I have a grid that has the "Add new record" button clicked showing teh textbox with Role: [TextBox] and the checkbox and cancel buttons below it.  When I click the checkbox button, I am firing the InsertCommand that uses an objectdatasource with three parameters (applicationId, applicationName, rolename).  roleName needs to be the value of the textbox.

My grid is called gvRoles.
My objectdatasource is called dsSecurity.

Is there just a couple of lines of code that I can use to get this value?

        protected void gvRoles_InsertCommand(object source, GridCommandEventArgs e)  
        {  
            //I need code here to retrieve the value of the textbox  
 
            dsSecurity.InsertMethod = "InsertRole";  
 
            String applicationId = cmbApplications.SelectedValue;  
            String applicationName = cmbApplications.SelectedItem.Text;  
            String roleName = "I need to set the role name from the textbox";  
            dsSecurity.InsertParameters["applicationId"].DefaultValue = applicationId;  
            dsSecurity.InsertParameters["applicationName"].DefaultValue = applicationName;  
            dsSecurity.InsertParameters["roleName"].DefaultValue = roleName;  
 
            gvRoles.DataBind();  
        } 
0
Daniel
Telerik team
answered on 22 Jun 2010, 10:03 AM
Hello Richard,

Depending on your scenario, you could extract the values or get them from the edit controls:
protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e)
{
    GridEditableItem item = e.Item as GridEditableItem;
 
    //Approach 1 - extract the value
    Hashtable table = new Hashtable();
    item.ExtractValues(table);
    var myValue = table["MyDataField"];
 
    //Approach 2 - get the value from the control
    RadTextBox tbox = item.FindControl("MyTextBox") as RadTextBox;
    var myValue2 = tbox.Text; 
}

Regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
ejb
Top achievements
Rank 2
answered on 26 Jun 2010, 10:08 PM
This was awesome thank you
Tags
Grid
Asked by
Richard
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Richard
Top achievements
Rank 1
ejb
Top achievements
Rank 2
Share this question
or