Based on the First ID
it has Four records data and based on the second ID it has three records.
Currently in view part it's displaying all the seven records in separate row but i required to display two rows but first row should contain four cords in a single row.
[HttpPost]
[MyExceptionHandler]
public ActionResult ViewModules(int id)
{
Domain_Bind();
dynamic mymodel = new ExpandoObject();
userType type = new userType();
List<ViewRoleModules> EmpList = type.GetRoleModulesViews(id);
string sRptModuleIDs = string.Empty;
foreach (ViewRoleModules emp in EmpList)
{
sRptModuleIDs += emp.ModuleID + ",";
}
if (sRptModuleIDs != "")
{
sRptModuleIDs = sRptModuleIDs.Remove(sRptModuleIDs.Length - 1, 1);
}
List<ViewRoleModules> RoleList;
List<ViewRoleModules> test = new List<ViewRoleModules>();
foreach (var rid in sRptModuleIDs.Split(','))
{
string RID = rid;
RoleList = type.GetSiteRoleModulesViews(rid);
foreach (ViewRoleModules vip in RoleList)
{
test.Add(new ViewRoleModules {
RoleName = vip.RoleName
});
}
}
return Json(test, JsonRequestBehavior.AllowGet);
}
in List<ViewRoleModules> test = new List<ViewRoleModules>();
list we are storing seven records but i need separate data based on ID
public List<ViewRoleModules> GetSiteRoleModulesViews(string rid)
{
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Admin"].ConnectionString))
{
List<ViewRoleModules> RoleList = new List<ViewRoleModules>();
SqlCommand com = new SqlCommand("MEDEIL_SiteRoleModules_SelectOne", conn);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.AddWithValue("@ModuleID", Convert.ToInt32(rid));
SqlDataAdapter da = new SqlDataAdapter(com);
DataTable dt = new DataTable();
conn.Open();
da.Fill(dt);
conn.Close();
foreach (DataRow dr in dt.Rows)
{
RoleList.Add(
new ViewRoleModules
{
RoleID = Convert.ToInt32(dr["RoleID"]),
RoleName = Convert.ToString(dr["RoleName"])
}
);
}
return RoleList;
}
}
in above pic it's is show all records separate row but i required to display two rows but first row should contain four cords in a single row.
<script>
$(document).ready(function () {
$("#DomainID").change(function () {
var id = $(this).val();
$("#example tbody tr").remove();
$.ajax({
type: 'POST',
url: '@Url.Action("ViewModules")',
dataType: 'json',
data: { id: id },
success: function (data) {
var items = '';
$.each(data, function (i, item) {
$("#findValue").show();
var rows = "<tr>"
+ "<td>" + i + "</td>"
+ "<td>" + item.ModuleName + "</td>"
+ "<td>" + item.Url + "</td>"
+ "<td>" + item.RoleName + "</td>"
+ "</tr>";
$('#example tbody').append(rows);
});
},
error: function (ex) {
var r = jQuery.parseJSON(response.responseText);
alert("Message: " + r.Message);
alert("StackTrace: " + r.StackTrace);
alert("ExceptionType: " + r.ExceptionType);
}
});
return false;
})
});
</script>
for example above image based on the Leads Id it's displaying multiple role name single row
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…