TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sneha K
1.2k
527
195.5k
How to bind dynamic table in Datatable in mvc?
Sep 18 2020 11:43 PM
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<dynamic> 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<dynamic>(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());
}
}
Reply
Answers (
2
)
Web Api In Asp.net Mvc ApiControlar
Getting cannot access child key error from the Web API