有两张表分别为cktz简写用c表示,js_ffry_js简写用j表示。
c表中 有个分发人员字段 例如xh为A的分发人员值为:张三、王五、李四、龙九
j表中 有个接收人员字段 例如xh为A的人员接收值为:张三,龙九问:怎样在查询c表的时候分发人员字段中 值为 张三、龙九的用红色表示?
下面是我的代码
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
string xh2 = e.Row.Cells[2].Text;
string name2 = e.Row.Cells[22].Text; string SqlConn = System.Configuration.ConfigurationSettings.AppSettings["ConnString"];
SqlConnection Conn = new SqlConnection(SqlConn);
Conn.Open();
string SqlStr0 = "select distinct(xh) from js_ffry_js";
SqlCommand Comm0 = new SqlCommand(SqlStr0, Conn);
SqlDataReader read0 = Comm0.ExecuteReader();
if (read0.Read())
{
string xh1 = read0["xh"].ToString();
string SqlConn1 = System.Configuration.ConfigurationSettings.AppSettings["ConnString"];
SqlConnection Conn1 = new SqlConnection(SqlConn1);
Conn1.Open();
string SqlStr1 = "select distinct(ry_name) from js_ffry_js";
SqlCommand Comm1 = new SqlCommand(SqlStr1, Conn1);
SqlDataReader read1 = Comm1.ExecuteReader();
if (read1.Read())
{
string name1 = read1["ry_name"].ToString();
if(name2.Trim().Contains(name1.Trim()) && xh1==xh2)
{ GridView1.Rows[i].Cells[22].ForeColor = System.Drawing.Color.Red;//这句话该怎样控制只是部分内容?
}
else
{
read1.Close();
Conn1.Close();
}
}
else
{
read0.Close();
Conn.Close();
}
}
}
c表中 有个分发人员字段 例如xh为A的分发人员值为:张三、王五、李四、龙九
j表中 有个接收人员字段 例如xh为A的人员接收值为:张三,龙九问:怎样在查询c表的时候分发人员字段中 值为 张三、龙九的用红色表示?
下面是我的代码
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
string xh2 = e.Row.Cells[2].Text;
string name2 = e.Row.Cells[22].Text; string SqlConn = System.Configuration.ConfigurationSettings.AppSettings["ConnString"];
SqlConnection Conn = new SqlConnection(SqlConn);
Conn.Open();
string SqlStr0 = "select distinct(xh) from js_ffry_js";
SqlCommand Comm0 = new SqlCommand(SqlStr0, Conn);
SqlDataReader read0 = Comm0.ExecuteReader();
if (read0.Read())
{
string xh1 = read0["xh"].ToString();
string SqlConn1 = System.Configuration.ConfigurationSettings.AppSettings["ConnString"];
SqlConnection Conn1 = new SqlConnection(SqlConn1);
Conn1.Open();
string SqlStr1 = "select distinct(ry_name) from js_ffry_js";
SqlCommand Comm1 = new SqlCommand(SqlStr1, Conn1);
SqlDataReader read1 = Comm1.ExecuteReader();
if (read1.Read())
{
string name1 = read1["ry_name"].ToString();
if(name2.Trim().Contains(name1.Trim()) && xh1==xh2)
{ GridView1.Rows[i].Cells[22].ForeColor = System.Drawing.Color.Red;//这句话该怎样控制只是部分内容?
}
else
{
read1.Close();
Conn1.Close();
}
}
else
{
read0.Close();
Conn.Close();
}
}
}
Text='<%# GetColor((int)Eval("id"),(GridViewRow)Container) %>'
public string GetColor(int id,GridViewRow row)
{
row.BackColor = Color.Red;
return "";
}
{
if (e.Row.RowIndex >= 0)
{
e.Row.BackColor = System.Drawing.Color.SkyBlue;//显示颜色,可自定义
}
}
{
switch (yh)
{
case "张三":
case "龙九":
return Color.Red;
default:
return Color.Green;
}
然后界面人员(美工或者售后服务人员)就可以为设计界面增加ForeColor属性:<asp:Label ID="Label1" runat="server" Text='<%# Bind("yh") %>' ForeColor='<%# BLL.GetYhColor((string)Eval("yh")) %>'></asp:Label>
1、case "张三":
case "龙九": 怎样转换为SQL语句?2、
<asp:Label ID="Label1" runat="server" Text='<%# Bind("yh") %>' ForeColor='<%# BLL.GetYhColor((string)Eval("yh")) %>'></asp:Label>我不是在label中显示的,是在gridview中该如何显示?
split再判断
gridview模板列label
能大概跟我讲下吗?