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 }); }
In this article i will show you, How to use BoundField of GridView in ASP.NET C#. Actually, BoundField is the Default field of GridView Control, used for DataBinding purpose. In my previous article i have already use this field with SQL DataSource control. Check mentioned below link:
[Video Contain BoundField + SQLDataSource + ADO.NET]
Now, Learn, How to create BoundField manually also bind them using ADO.NET Technology with Database table. First to create a database table, insert some data into table. Prepare BoundField like this:
<asp:GridView ID="g1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Identification No" />
<asp:BoundField DataField="Name" HeaderText="Name of User" />
</Columns>
</asp:GridView>
<asp:GridView ID="g1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Identification No" />
<asp:BoundField DataField="Name" HeaderText="Name of User" />
</Columns>
</asp:GridView>
Code Behind Code:
using System;
using System.Web.UI;
using System.Data.SqlClient;
using System.Configuration;
public partial class BoundFieldExample : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
bindGrid();
}
}
private void bindGrid()
{
SqlConnection con = new SqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
con.Open();
SqlCommand cmd= new SqlCommand();
cmd.CommandText = "select * From [usertable]";
cmd.Connection =con;
SqlDataReader rd= cmd.ExecuteReader();
g1.DataSource =rd;
g1.DataBind();
}
}
using System;
using System.Web.UI;
using System.Data.SqlClient;
using System.Configuration;
public partial class BoundFieldExample : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
bindGrid();
}
}
private void bindGrid()
{
SqlConnection con = new SqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
con.Open();
SqlCommand cmd= new SqlCommand();
cmd.CommandText = "select * From [usertable]";
cmd.Connection =con;
SqlDataReader rd= cmd.ExecuteReader();
g1.DataSource =rd;
g1.DataBind();
}
}
Code Generates the following output:
Comments
Post a Comment