如何给(课程或一组),每个表在这个HTMLTABLE一个特定的颜色? [英] How to give each table (or group of courses) a specific color in this HTMLTable?
问题描述
我有以下的数据库设计:
Employee表:用户名,姓名,工作...等
课程表:CourseID,课程名,组ID
Employee_Courses表:雇员,CourseID
组表:组ID,组名
块引用>的 注意:每个表中的第一个属性是主键的
我已经开发了一个矩阵,显示所有员工和所有课程。因为我有三组疗程三,我需要有一个表为每个组的课程。我开发这个矩阵来查看使用GridView控件Repeater控件中的信息。另外,我再次开发利用进入了HTMLTABLE在C#中的数据。一切工作正常。我现在需要的是给每个组特定的颜色。例如,组#1用蓝色和组#2与黄色色等。我在C#这样苦苦挣扎。
所以,任何人都可以,请帮助我这个问题?
在ASP.NET和C#我的code是如下:
ASP.NET:
< ASP:占位符ID =PLACEHOLDER1=服务器/> &所述;% - 这SqlDataSource的是用于检索的GroupID - %GT;
< ASP:SqlDataSource的ID =SqlDataSource1=服务器
的ConnectionString =下;%$的ConnectionStrings:testConnectionString%>中
的SelectCommand =SELECT [ID] FROM [组]>< / ASP:SqlDataSource的>
<% - 这是的SqlDataSource用于检索雇员和安全培训coruses的信息 - %GT;
< ASP:SqlDataSource的ID =SqlDataSource2=服务器
的ConnectionString =下;%$的ConnectionStrings:testConnectionString%>中
SelectCommandType =StoredProcedure的的SelectCommand =kbiReportFilterEx pression =[DivisionName]像'{0}%'> < SelectParameters>
< ASP:参数名称=组ID/>
< / SelectParameters> < FilterParameters>
< ASP:ControlParameter控件ID =ddlDivisionNAME =DivisionName
属性名=的SelectedValue类型=字符串/>
< / FilterParameters> < / ASP:SqlDataSource的> <% - 过滤通过分部 - %GT;
< ASP:SqlDataSource的ID =sqlDataSourceDivision=服务器
的ConnectionString =下;%$的ConnectionStrings:testConnectionString%>中
的SelectCommand =从[师] [DivisionName]>< / ASP:SqlDataSource的> < ASP:按钮的ID =updateButton=服务器的OnClick =updateButton_Click文本=更新/>C#:
保护无效的Page_Load(对象发件人,EventArgs的发送)
{ 数据视图DV2 =(数据视图)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
的foreach(在DV2 DataRowView的组)
{
SqlDataSource2.SelectParameters [0] = .DefaultValue集团[0]的ToString();
//创建一个新的对象HTMLTABLE
HTMLTABLE表=新HTMLTABLE(); DataView的DV =(数据视图)SqlDataSource2.Select(DataSourceSelectArguments.Empty);
诠释列= dv.Table.Columns.Count;
诠释行= dv.Count; //表的格式化相关的属性
table.Border = 2;
table.CellPadding = 3;
table.CellSpacing = 3;
table.Width =900px; //获得CSS样式
table.Attributes [类] =MGRID; //创建一个新的HtmlTableRow和HtmlTableCell对象
HtmlTableRow排;
HtmlTableRow头=新HtmlTableRow();
HtmlTableCell细胞;
//用于将头表
的foreach(在dv.Table.Columns的DataColumn列)
{
HtmlTableCell headerCell =新HtmlTableCell(日);
headerCell.InnerText = column.Caption;
header.Cells.Add(headerCell);
}
table.Rows.Add(头); //添加行到表圈
的foreach(在DV DataRowView的数据行)
{
行=新HtmlTableRow();
row.BgColor =黄;
//添加细胞循环
对于(INT J = 0; J<列; J ++)
{
细胞=新HtmlTableCell();
如果(J 4;)
{
cell.InnerText =数据行[J]的ToString();
}
其他
{ 复选框复选框=新的复选框(); INT checkBoxColumns = dv.Table.Columns.Count - 5;
字符串fieldValue方法=数据行[J]的ToString();
字符串是= fieldvalue.Split(新的String [] {,},StringSplitOptions.RemoveEmptyEntries)[1];
字符串courseid = fieldvalue.Split(新的String [] {,},StringSplitOptions.RemoveEmptyEntries)[0];
checkbox.ID = row.Cells [3] .InnerText +,+ courseid.Trim();
checkbox.Checked = yes.Equals(是);
cell.Controls.Add(复选框); } //小区添加到当前行
row.Cells.Add(细胞);
} //行添加到表
table.Rows.Add(行);
} //表添加到页面
PlaceHolder1.Controls.Add(表); }
}
解决方案你能不能做这样的事情?
先在你的样式表为您想要的颜色创建一个类。
.redcell {背景:#FF0000;}
然后在code,你要添加你的细胞。
如果(集团==mygroup的)
{
cell.Attributes.Add(类,redcell);
}I have the following database design:
Employee Table: Username, name, Job... etc
Course Table: CourseID, CourseName, GroupID
Employee_Courses Table: EmployeeID, CourseID
Group Table: GroupID, GroupName
NOTE: The first attribute in each table is the primary key
I have developed a matrix that shows all employees and all courses. Since I have three groups of courses three, I need to have one table for each group of courses. I developed this matrix to view the information using GridView inside a Repeater control. Also, I developed again for entering data using the HTMLTable in C#. Everything works fine. What I need now is to give each group specific color. For example, Group#1 with Blue color and Group#2 with Yellow color and so on. I am struggling now with doing this in C#.
So could anyone please help me with this issue?
My code in ASP.NET and C# is as following:
ASP.NET:
<asp:PlaceHolder ID="PlaceHolder1" runat="server" /> <%--This SqlDataSource is for retrieving the GroupID--%> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:testConnectionString %>" SelectCommand="SELECT [ID] FROM [groups]"></asp:SqlDataSource> <%--This SqlDataSource is for retrieving the information of the employees and the safety training coruses--%> <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:testConnectionString %>" SelectCommandType="StoredProcedure" SelectCommand="kbiReport" FilterExpression="[DivisionName] like '{0}%'"> <SelectParameters> <asp:Parameter Name="GroupID"/> </SelectParameters> <FilterParameters> <asp:ControlParameter ControlID="ddlDivision" Name="DivisionName" PropertyName="SelectedValue" Type="String" /> </FilterParameters> </asp:SqlDataSource> <%--Filtering by Division--%> <asp:SqlDataSource ID="sqlDataSourceDivision" runat="server" ConnectionString="<%$ ConnectionStrings:testConnectionString %>" SelectCommand="SELECT [DivisionName] FROM [Divisions]"></asp:SqlDataSource> <asp:Button ID="updateButton" runat="server" OnClick="updateButton_Click" Text="Update" />
C#:
protected void Page_Load(object sender, EventArgs e) { DataView dv2 = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty); foreach (DataRowView group in dv2) { SqlDataSource2.SelectParameters[0].DefaultValue = group[0].ToString(); //create a new HtmlTable object HtmlTable table = new HtmlTable(); DataView dv = (DataView)SqlDataSource2.Select(DataSourceSelectArguments.Empty); int columns = dv.Table.Columns.Count; int rows = dv.Count; //table's formating-related properties table.Border = 2; table.CellPadding = 3; table.CellSpacing = 3; table.Width = "900px"; //to get the css style table.Attributes["class"] = "mGrid"; //create a new HtmlTableRow and HtmlTableCell objects HtmlTableRow row; HtmlTableRow header = new HtmlTableRow(); HtmlTableCell cell; //for adding the headers to the table foreach (DataColumn column in dv.Table.Columns) { HtmlTableCell headerCell = new HtmlTableCell("th"); headerCell.InnerText = column.Caption; header.Cells.Add(headerCell); } table.Rows.Add(header); //loop for adding rows to the table foreach (DataRowView datarow in dv) { row = new HtmlTableRow(); row.BgColor = "yellow"; //loop for adding cells for (int j = 0; j < columns; j++) { cell = new HtmlTableCell(); if (j < 4) { cell.InnerText = datarow[j].ToString(); } else { CheckBox checkbox = new CheckBox(); int checkBoxColumns = dv.Table.Columns.Count - 5; string fieldvalue = datarow[j].ToString(); string yes = fieldvalue.Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries)[1]; string courseid = fieldvalue.Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries)[0]; checkbox.ID = row.Cells[3].InnerText + "," + courseid.Trim(); checkbox.Checked = yes.Equals("Yes"); cell.Controls.Add(checkbox); } //add the cell to the current row row.Cells.Add(cell); } //add the row to the table table.Rows.Add(row); } //add the table to the page PlaceHolder1.Controls.Add(table); } }
解决方案could you not do something like this?
first create a class in your style sheet for the color you want.
.redcell{background:#ff0000;}
then in your code where you're adding your cells.
if(Group=="mygroup") { cell.Attributes.Add("class","redcell"); }
这篇关于如何给(课程或一组),每个表在这个HTMLTABLE一个特定的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!