I want to show Components in a tabs , so first of all create few components. In this project we have three components, First View Component public class AllViewComponent : ViewComponent { private readonly UserManager<ApplicationUser> _userManager; public AllViewComponent(UserManager<ApplicationUser> userManager) { _userManager = userManager; } public async Task<IViewComponentResult> InvokeAsync() { List<StudentViewModel> allUsers = new List<StudentViewModel>(); var items = await _userManager.Users.ToListAsync(); foreach (var item in items) { allUsers.Add(new StudentViewModel {Id=item.Id, EnrollmentNo = item.EnrollmentNo, FatherName = item.FatherName, Name = item.Name, Age = item.Age, Birthdate = item.Birthdate, Address = item.Address, Gender = item.Gender, Email = item.Email }); }
First create instance of DataTable class, which is inside in System.Data namespace. After that you make columns and rows inside the DataTable. First create columns with their data type also insert rows data in it.
Source Code
<div><asp:GridView ID="GridView1" runat="server">
<HeaderStyle BackColor ="Green" ForeColor ="Orange" />
<RowStyle BackColor ="Black" ForeColor ="White" />
</asp:GridView><br />
<asp:Button ID="B1" runat="server" Text="Bind GridView" onclick="B1_Click" />
</div>
Business Logic Code
using System;using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
public partial class Default4 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void B1_Click(object sender, EventArgs e)
{
DataTable datatable = new DataTable();
datatable.Columns.Add("serial Number", typeof(Int32));
datatable.Columns.Add("Name", typeof(string));
datatable.Columns.Add("Address", typeof(string));
datatable.Rows.Add(1, "Jacob", "USA");
datatable.Rows.Add(2, "Lefore", "USA");
datatable.Rows.Add(3, "Bill", "UK");
datatable.Rows.Add(4, "Smith", "UK");
GridView1 .DataSource =datatable;
GridView1.DataBind ();
}
}
Comments
Post a Comment