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

RadGrid with Add New button

3 Answers 111 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
: Arumuga Vignesh
Top achievements
Rank 1
: Arumuga Vignesh asked on 19 Aug 2013, 07:59 AM

Hi,

 
I am using radgrid with Add New Record button in it.

On click of Add New Record button ,there are two GridBoundColumn from which one GridBoundColumn had to be populated after entering data in another GridBoundColumn.

For Example: Comments should be populated once the user enters country name in country GridBoundColumn.

Please provide a sample code  or reference link to execute this functionality.

Thanks

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 19 Aug 2013, 12:40 PM
Hi,

Please try the following code snippet to  populate the one GridBoundColumn which is TextBox in insert mode depending upon the value of the other TextBox.

C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted)
    {
        GridEditFormInsertItem insert= (GridEditFormInsertItem)e.Item;
        TextBox TextBox1 = (TextBox)insert["UniqueName1"].Controls[0];
        TextBox TextBox2 = (TextBox)insert["UniqueName2"].Controls[0];
        TextBox1.AutoPostBack = true;
        TextBox1.TextChanged += new EventHandler(txt1_TextChanged);
    }
}
void txt1_TextChanged(object sender, EventArgs e)
{
    TextBox TextBox1 = (TextBox)sender;
    GridEditFormInsertItem insertitem = (GridEditFormInsertItem)TextBox1.NamingContainer;
    TextBox TextBox2 = (TextBox)insertitem["UniqueName2"].Controls[0];
    if (TextBox1.Text == "India")
    {
        TextBox2.Text = "New Delhi";
    }
}

Thanks,
Shinu.
0
: Arumuga Vignesh
Top achievements
Rank 1
answered on 28 Aug 2013, 01:30 PM

The solution is working fine.

But,Insert button is not working after entering all the fields in radgrid and comments are populated in the last textbox.

On click of insert button,it is not hitting radgrid_InsertCommand event.

Please provide the solution for this.

0
Shinu
Top achievements
Rank 2
answered on 29 Aug 2013, 05:32 AM
Hi Arumuga Vignesh,

Unfortunately I couldn't replicate the issue. This is an undesired behaviour. Here is the complete code snippet I tried. Please take a look into it.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" DataSourceID="SqlDataSource1"   OnItemCreated="RadGrid1_ItemCreated" OnInsertCommand="RadGrid1_InsertCommand">  
    <MasterTableView DataKeyNames="OrderID" CommandItemDisplay="Top">
        <Columns>
            <telerik:GridBoundColumn DataField="Country" UniqueName="Country">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="City" UniqueName="City">
            </telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted)
    {
        GridEditFormInsertItem insert= (GridEditFormInsertItem)e.Item;
        TextBox TextBox1 = (TextBox)insert["Country"].Controls[0];
        TextBox TextBox2 = (TextBox)insert["City"].Controls[0];
        TextBox1.AutoPostBack = true;
        TextBox1.TextChanged += new EventHandler(txt1_TextChanged);
    }
}
void txt1_TextChanged(object sender, EventArgs e)
{
    TextBox TextBox1 = (TextBox)sender;
    GridEditFormInsertItem insertitem = (GridEditFormInsertItem)TextBox1.NamingContainer;
    TextBox TextBox2 = (TextBox)insertitem["City"].Controls[0];
    if (TextBox1.Text == "India")
    {
        TextBox2.Text = "New Delhi";
    }
}
protected void RadGrid1_InsertCommand(object sender, GridCommandEventArgs e)
{
  //your code
}

Please provide your code so that i can replicate the issue at my end.

Thanks,
Shinu.
Tags
General Discussions
Asked by
: Arumuga Vignesh
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
: Arumuga Vignesh
Top achievements
Rank 1
Share this question
or