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

radgrid add new

1 Answer 85 Views
Grid
This is a migrated thread and some comments may be shown as answers.
JJ
Top achievements
Rank 1
JJ asked on 05 Jun 2012, 05:48 PM
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

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 06 Jun 2012, 12:20 PM
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.
Tags
Grid
Asked by
JJ
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or