Create Role List in Gridview with Ajax datatable in asp.net C#
Overview:
This article explains how to create role list in Gridview with Ajax datatable in asp.net C# in role master page in it management system. we have started a new project for learning asp.net. The project name is IT Management System and given Youtube link IT Management System (IMS Session-7) The following steps here.ππ₯
Step 1:
✍ Open Already Created IT Management System Project Folder Location
✍ It's open in visual studio
| Open Already created project in Visual Studio |
Step 2 : Add following script in Role Master Page Header section
<script src="Design/template/vendors/datatables.net/jquery.dataTables.js"></script><script src="Design/template/js/data-table.js"></script><script src="Design/template/vendors/datatables.net-bs4/dataTables.bootstrap4.js"></script><link href="Design/template/vendors/datatables.net-bs4/dataTables.bootstrap4.css" rel="stylesheet" /><script type="text/javascript">$(function () {$('[id*=gridlistrole]').prepend($("<thead></thead>").append($(this).find("tr:first"))).DataTable({"pageLength": 4,"lengthMenu": [[4, 10, 20, 50, 100], [4, 10, 20, 50, 100]],"responsive": true,"sPaginationType": "full_numbers"});$('#gridlistrole').DataTable().ajax.reload();});</script>
Step 3 : Add Gridview in Role master page
<div class="row">
<div class="col-lg-3"></div>
<asp:GridView ID="gridlistrole" CssClass="table table-bordered table-striped table-hover" AutoGenerateColumns="false" runat="server" EmptyDataText="No Records Found">
<Columns>
<asp:BoundField DataField="Sno" HeaderText="Sno" />
<asp:BoundField DataField="Id" Visible="false" HeaderText="Id" />
<asp:BoundField DataField="Role" HeaderText="Role" />
<asp:BoundField DataField="Description" HeaderText="Description" />
</Columns>
</asp:GridView>
</div>
Step 4: Add DAL class
public DataTable ListRole()
{
DataTable dt = new DataTable();
try
{
using (SqlConnection con = new SqlConnection(constring))
{
objcmd.CommandText = "prListRole";
objcmd.CommandType = CommandType.StoredProcedure;
objcmd.Connection = con;
con.Open();
SqlDataAdapter da = new SqlDataAdapter(objcmd);
da.Fill(dt);
con.Close();
}
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
return dt;
}
Step 5: Add BAL class
public DataTable ListRole(){return objadmindal.ListRole();}
Step 6: Add RoleMaster.aspx.cs page
public void BindRoleList()
{
DataTable list = objadminbal.ListRole();
if (list.Rows.Count > 0)
{
gridlistrole.DataSource = list;
gridlistrole.DataBind();
}
else
{
gridlistrole.DataBind();
}
}

No comments:
Post a Comment