- Home
- Forum
- ASP.NET Core
- Edit GRID Row
Edit GRID Row
Hi all,
It's possible create a cascading dropdownlist populate with a stored procedure in the edit of the row?
These are my two ddl in edit:
col.Field("MA_StatusCode").HeaderText("Reallocated status code").AllowEditing(true).EditType(EditingType.Dropdown).DataSource((List<object>)ViewBag.alarms).ForeignKeyField("MA_StatusCode").AllowResizing().Width(150).Add();
col.Field("FullDescription").HeaderText("Reallocated Full Description").EditType(EditingType.Dropdown).DataSource((List<object>)ViewBag.FullAlarm).ForeignKeyField("FullDescription").AllowResizing().Width(400).Add();
It's possible?
Thanks,
Nicholas
SIGN IN To post a reply.
1 Reply
SS
Seeni Sakthi Kumar Seeni Raj
Syncfusion Team
January 23, 2017 12:33 PM UTC
Hi Nicholas,
Thanks for contacting Syncfusion Support.
The Column dataSource will accept only the list of text/value pair as an input. So we suggest to convert the StoredProcedure result to the list of text/value pair and assign them to the corresponding column. Refer to the following code example and API reference.
|
public IActionResult Index()
{
String strConnString = ConfigurationManager.ConnectionStrings["NORTHWNDConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "Shipping";
cmd.Connection = con;
con.Open();
List<object> dropObj = new List<object>();
using (SqlDataReader dr = cmd.ExecuteReader())
{
while (dr.Read())
{
//Convert them to text/value pair
dropObj.Add(new { text = dr.GetValue(0).ToString(), value = dr.GetValue(0).ToString() });
}
}
con.Close();
ViewBag.dropObj = dropObj;
ViewBag.GridData = new NorthwindDataContext().OrdersViews.ToList();
return View();
}
@{Html.EJ().Grid<object>("FlatGrid")
.Datasource((IEnumerable<object>)ViewBag.GridData)
.AllowPaging()
.Columns(col =>
{
.. .
.. .
//Dropdown column
col.Field("ShipCountry").HeaderText("Ship Country")
.DataSource((IEnumerable<object>)ViewBag.dropObj)
.EditType(EditingType.Dropdown).Add();
}).Render();
} |
Note: In this, we have read the Shipping a Stored Procedure and bind ShipCountry column as a text/value pair input to the DropDown DataSource.
We could also have noticed that you have used the foreignkey in your code example but you have missed a ForeignKeyValue API for the corresponding column. To Render the ForeignKey column ForeignKeyValue, ForeignKeyField and DataSource are important for a column. Refer to the following code example and help Documents.
|
@{Html.EJ().Grid<object>("FlatGrid")
.Datasource((IEnumerable<object>)ViewBag.GridData)
.AllowPaging()
.Columns(col =>
{
.. .
. . .
//ForeignKey column
col.Field("EmployeeID").HeaderText("Employee Name")
.ForeignKeyField("EmployeeID")
.ForeignKeyValue("FirstName")
.DataSource((IEnumerable<object>)ViewBag.forObj)
.TextAlign(TextAlign.Left).Add();
}).Render();
}
|
Regards,
Seeni Sakthi Kumar S.
SIGN IN To post a reply.
- 1 Reply
- 2 Participants
-
NP Nicholas Picardi
- Jan 20, 2017 01:51 PM UTC
- Jan 23, 2017 12:33 PM UTC