radgrid add new

2 posts, 0 answers
  1. JJ
    JJ avatar
    147 posts
    Member since:
    May 2010

    Posted 05 Jun 2012 Link to this post

    When radgrid at  add new mode, when I enter ID (text box), populate the rest of the informatoin on the row (name, phone), this happens  when the user exit the ID text box. ( get the ID entered on the grid cell, go to database get the rest of the info). Is this radgrid can do? Do you have a similar example?

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

    Posted 06 Jun 2012 Link to this post

    Hi,

    Here is the sample code I tried based on your scenario.

    ASPX:
    <telerik:RadGrid ID="rdgdr1" runat="server" AutoGenerateColumns="false" AutoGenerateEditColumn="false"onitemcommand="rdgdr1_ItemCommand">
     <MasterTableView>
       <columns>
         <telerik:GridBoundColumn UniqueName="OrderID" DataField="OrderID" HeaderText="OrderID" ></telerik:GridBoundColumn>
         <telerik:GridBoundColumn UniqueName="EmployeeID" DataField="EmployeeID" HeaderText="EmployeeID"></telerik:GridBoundColumn>
       </columns>
     </MasterTableView>

    C#:
    protected void rdgdr1_ItemCommand(object sender, GridCommandEventArgs e)
    {
     if (e.CommandName == RadGrid.InitInsertCommandName)
        {
            e.Canceled = true;
            e.Item.OwnerTableView.InsertItem();
            GridEditableItem insertedItem = e.Item.OwnerTableView.GetInsertItem();
            GridEditFormItem editFormItem = insertedItem as GridEditFormItem;
            TextBox OrderID = (TextBox)editFormItem["OrderID"].Controls[0];
            string Order = OrderID.Text;
            OrderID.Attributes.Add("OnBlur", "javascript:funBlur();");     
        }
     if (e.CommandName == "insert")
        {
            GridEditableItem insertedItem = e.Item.OwnerTableView.GetInsertItem();
            GridEditFormItem editFormItem = insertedItem as GridEditFormItem;
            TextBox OrderID = (TextBox)editFormItem["OrderID"].Controls[0];
            string Order = OrderID.Text;
            conn.Open();
            string selectFilterQuery = "select EmployeeID from [Orders] where OrderID = '" + Order + "'";
            SqlCommand.CommandText = selectFilterQuery;
            SqlCommand.Connection = conn;
            SqlDataAdapter adapter = new SqlDataAdapter(selectFilterQuery, conn);
            DataTable dt = new DataTable();
            adapter.Fill(dt);
            TextBox sh = (TextBox)editFormItem["EmployeeID"].Controls[0];
            sh.Text = dt.Rows[0][0].ToString();
            conn.Close();
        }
    }

    Javascript:
    <script type="text/javascript">
    function funBlur()
    {
        var grid = $find("<%=rdgdr1.ClientID %>");
        var masterTable = grid.get_masterTableView();
        masterTable.fireCommand("insert","");
    }
    </script>

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top