اگر می خواهید سلول های Gridview را رنگ آمیزی کنید و نحوه دسترسی به مقادیر سلول را یاد بگیرید، این مقاله به شما کمک می کند.
این مقاله درباره نحوه تنظیم یا تغییر رنگ پسزمینه ردیف انتخابی ASP.Net GridView به صورت برنامهنویسی است.
در اینجا به سراغ کد فایل cs می رویم
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
namespace gridcolor {
public partial class WebForm1: System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
DataTable dt = new DataTable();
dt.Columns.add("Hobbies");
//here only one column for easy understanding
dt.Rows.add("I love C# corner")
mygrid.datasource = dt;
mygrid.databind();
//for perticular cell //here it has only 1 cell (0,0)
myGrid.Rows[i].Cells[j].Style.BackColor = system.drawing.color.Red;
//incase you want to fill all rows
for (int i = 0; i < myGrid.Rows.Count; i++) {
for (int j = 0; j < myGrid.Rows[i].Cells.Count; j++) {
myGrid.Rows[i].Cells[j].Style.BackColor = /*color you want*/
}
}
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
namespace gridcolor {
public partial class WebForm1: System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
DataTable dt = new DataTable();
dt.Columns.add("Hobbies");
//here only one column for easy understanding
dt.Rows.add("I love C# corner")
mygrid.datasource = dt;
mygrid.databind();
//for perticular cell //here it has only 1 cell (0,0)
myGrid.Rows[i].Cells[j].Style.BackColor = system.drawing.color.Red;
//incase you want to fill all rows
for (int i = 0; i < myGrid.Rows.Count; i++) {
for (int j = 0; j < myGrid.Rows[i].Cells.Count; j++) {
myGrid.Rows[i].Cells[j].Style.BackColor = /*color you want*/
}
}
}
}
}
اکنون نگاهی کوتاه به aspx من داشته باشید
کد صفحه
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
body
{
font-family: Arial;
font-size: 10pt;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="myGrid" runat="server" AutoGenerateColumns="false" >
<Columns>
<asp:BoundField DataField="Hobbies" HeaderText="Hobbies" ItemStyle-Width="150" />
<head runat="server">
<title></title>
<style type="text/css">
body
{
font-family: Arial;
font-size: 10pt;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="myGrid" runat="server" AutoGenerateColumns="false" >
<Columns>
<asp:BoundField DataField="Hobbies" HeaderText="Hobbies" ItemStyle-Width="150" />
</Columns>
</asp:GridView>
</form>
</body>
</html>
امیدوارم که آموزش را به راحتی درک کرده باشید🙂
اشتراک گذاری مراقبت است. با دوستان برنامه نویس خود به اشتراک بگذارید.