Hi i want to bind my table with datatable dynamically. I wrote upto DAL and Controller. But I am totally struck how to bind this table in view . I tried web grid but requirement is not web grid i want to bind the table column and row dynamically in datatable. Anyone help me to resolve this issue.Thanks
My DAL
- public List
GetData( string Year, string SID, string Type_ID) - {
- ISqlDBHelper sqlDBHelper = new SqlDBHelper();
- SqlParameter[] parameters = new SqlParameter[]{
- new SqlParameter("@Year",Year),
- new SqlParameter("@ConID",SID),
- new SqlParameter("@TypeID",Type_ID),
- };
- using (DataTable table = sqlDBHelper.ExecuteParamerizedSelectCommand("GetDetails", CommandType.StoredProcedure, parameters))
- {
- var model = new List
(table.Rows.Count); - if (table.Rows.Count > 0)
- {
- foreach (DataRow row in table.Rows)
- {
- var obj = (IDictionary<string, object>)new ExpandoObject();
- foreach (DataColumn col in table.Columns)
- {
- obj.Add(col.ColumnName, row[col.ColumnName]);
- }
- model.Add(obj);
- }
- }
- return model;
- }
- }
My Controller
- public PartialViewResult GetDetails(string Year = "3", string SID = "1", string TypeID = "1")
- {
- try
- {
- SBAL sBal = new SBAL();
- return PartialView(sBal .GetData(Year, SID , TypeID ));
- }
- catch (Exception ex)
- {
- Common.AddModel_Log4Net();
- throw new Exception(ex.ToString());
- }
- }
Sneha KPosted Sep 19, 2020, 1:22 AM
Farhan AhmedPosted Sep 19, 2020, 12:52 AM