如何将数据填充到devexpress gridview
How to populate data into devexpress gridview
我刚刚学习如何在 asp.net mvc 中使用 devexpress 构建 Web 应用程序。我在尝试绑定 DevExpress.GridView.
时遇到问题
这是我的控制器:
public ActionResult UploadedIndividualViewPartial()
{
using (SqlConnection cn = new SqlConnection(@"Server = DESKTOP-FSET3FF; Database = ECIF_DATA; User Id = sa; Password = Copoe113"))
{
SqlCommand cmd = new SqlCommand("select * from UploadedPotentialDataIndividu", cn);
cn.Open();
ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
}
return PartialView("_UploadedPotentialDataIndividual"); // How can i pass data from sql query above into grid view
}
这是我的 PartialView:
@{
var grid = Html.DevExpress().GridView(settings =>
{
settings.Name = "GridApproveView";
settings.CallbackRouteValues = new { Controller = "UploadedPotentialDataMerge", Action = "UploadedIndividualViewPartial"};
settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);
settings.SettingsPager.PageSize = 32;
settings.Height = 200;
settings.Settings.VerticalScrollBarMode = ScrollBarMode.Auto;
settings.ControlStyle.Paddings.Padding = System.Web.UI.WebControls.Unit.Pixel(0);
settings.ControlStyle.Border.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(0);
settings.ControlStyle.BorderBottom.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(1);
settings.SettingsEditing.ShowModelErrorsForEditors = true;
settings.SettingsEditing.Mode = GridViewEditingMode.EditFormAndDisplayRow;
settings.CommandColumn.Visible = true;
settings.ClientSideEvents.SelectionChanged = "SelectionApproveChanged";
settings.KeyFieldName = "ECIFCandidate";
settings.SettingsDetail.AllowOnlyOneMasterRowExpanded = false;
settings.SettingsDetail.ShowDetailRow = true;
settings.CommandColumn.ShowSelectCheckbox = true;
settings.Settings.ShowFilterBar = GridViewStatusBarMode.Visible;
settings.SetDetailRowTemplateContent(c =>
{
ViewContext.Writer.Write(
"ECIF REF: <b>" +
DataBinder.Eval(c.DataItem, "ECIFCandidate") + "</b>"
);
Html.RenderAction("GridDetailViewPartial", new { ECIF = DataBinder.Eval(c.DataItem, "ECIFCandidate") });
});
});
}@grid.Bind(Model).GetHtml()
我仍然想知道如何将控制器中 sql 查询的数据绑定到局部视图中。你能告诉我一个简单的代码怎么做吗?
从动作中传递数据
return PartialView("_UploadedPotentialDataIndividual", ds[0]);
并添加到局部视图的顶部
@model System.Data.DataTable
我刚刚学习如何在 asp.net mvc 中使用 devexpress 构建 Web 应用程序。我在尝试绑定 DevExpress.GridView.
时遇到问题这是我的控制器:
public ActionResult UploadedIndividualViewPartial()
{
using (SqlConnection cn = new SqlConnection(@"Server = DESKTOP-FSET3FF; Database = ECIF_DATA; User Id = sa; Password = Copoe113"))
{
SqlCommand cmd = new SqlCommand("select * from UploadedPotentialDataIndividu", cn);
cn.Open();
ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
}
return PartialView("_UploadedPotentialDataIndividual"); // How can i pass data from sql query above into grid view
}
这是我的 PartialView:
@{
var grid = Html.DevExpress().GridView(settings =>
{
settings.Name = "GridApproveView";
settings.CallbackRouteValues = new { Controller = "UploadedPotentialDataMerge", Action = "UploadedIndividualViewPartial"};
settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);
settings.SettingsPager.PageSize = 32;
settings.Height = 200;
settings.Settings.VerticalScrollBarMode = ScrollBarMode.Auto;
settings.ControlStyle.Paddings.Padding = System.Web.UI.WebControls.Unit.Pixel(0);
settings.ControlStyle.Border.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(0);
settings.ControlStyle.BorderBottom.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(1);
settings.SettingsEditing.ShowModelErrorsForEditors = true;
settings.SettingsEditing.Mode = GridViewEditingMode.EditFormAndDisplayRow;
settings.CommandColumn.Visible = true;
settings.ClientSideEvents.SelectionChanged = "SelectionApproveChanged";
settings.KeyFieldName = "ECIFCandidate";
settings.SettingsDetail.AllowOnlyOneMasterRowExpanded = false;
settings.SettingsDetail.ShowDetailRow = true;
settings.CommandColumn.ShowSelectCheckbox = true;
settings.Settings.ShowFilterBar = GridViewStatusBarMode.Visible;
settings.SetDetailRowTemplateContent(c =>
{
ViewContext.Writer.Write(
"ECIF REF: <b>" +
DataBinder.Eval(c.DataItem, "ECIFCandidate") + "</b>"
);
Html.RenderAction("GridDetailViewPartial", new { ECIF = DataBinder.Eval(c.DataItem, "ECIFCandidate") });
});
});
}@grid.Bind(Model).GetHtml()
我仍然想知道如何将控制器中 sql 查询的数据绑定到局部视图中。你能告诉我一个简单的代码怎么做吗?
从动作中传递数据
return PartialView("_UploadedPotentialDataIndividual", ds[0]);
并添加到局部视图的顶部
@model System.Data.DataTable