RadGrid with Add New button

4 posts, 0 answers
  1. : Arumuga Vignesh
    : Arumuga Vignesh  avatar
    21 posts
    Member since:
    Jul 2013

    Posted 19 Aug 2013 Link to this post

    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

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 19 Aug 2013 Link to this post

    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.
  3. : Arumuga Vignesh
    : Arumuga Vignesh  avatar
    21 posts
    Member since:
    Jul 2013

    Posted 28 Aug 2013 Link to this post

    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.

  4. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 29 Aug 2013 Link to this post

    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.
Back to Top