ASP .NET DataGrid Dynamic(OnrowDatabound)通过标签显示Diverentz通过Collor找到所有单元格
我有一个特殊的问题要解决,可以找到解决方案。
DataGrid绑定到SQL查询,并且具有可检测到历史更改的动态内部连接。用户可以选择任何导入的数据以显示多达10个数据库之间的差异。
列的标签是Epreis和bpreis。
现在,我需要在行上找到所有Epreis和所有bpreis鸡蛋5xepreis。
funktion1 bpreis最便宜的背景颜色=绿色 Secend Preis背景颜色= Yello 3 ...... 10.
在Epreis上也是如此。
C#
protected void run_Click(object sender, EventArgs e)
{
SqlDataAdapter adp1 = new SqlDataAdapter(getSearch, con);
DataTable dt1 = new DataTable();
adp1.Fill(dt1);
mergeresult.DataSource = dt1;
mergeresult.DataBind();
}
protected void mergeresult_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex >= 0)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
for (int i = 0; i < e.Row.count - 1; i++)
{
for (int cellIndex = 0; cellIndex < Row.Cells.Count; cellIndex++)
{
if ((Label)e.row.cell.cellindex == "EPreis")
{
//? Howto find all PReis and EPreis in row.count
// is posible to put cell[x] and cell.text in array
// and at end of row sorting array 1 to x to colering
// the cell.
// Later to expand funktion Tolltip or mous over to show %
// Diverent to cheeperst
}
}
}
}
}
}
我找到了一个解决方案,但它仍然无法正常工作。 最高和最低的价格有时会逆转。
if (e.Row.RowIndex >= 0)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int totalRow = mergeresult.Rows.Count;
int totalColumns = mergeresult.Columns.Count;
for (int i = 0; i < totalRow + 1; i++)
{
//int anzahl = (int)ViewState["Anzahlfrom"];
//string[] NumOfPreisfields = new string[anzahl];
var Preisfields = new List<string>();
var Preisfieldslist = new List<(int cellNr, string Preis, string color)>();
for (int j = 0; j < e.Row.Cells.Count; j++)
{
var SearchColumnName = "EK";
DataControlFieldCell cell = (DataControlFieldCell)e.Row.Cells[j];
if (cell.ContainingField is BoundField)
{
if (((BoundField)cell.ContainingField).DataField.Contains(SearchColumnName))
{
Preisfields.Add(j.ToString());
Preisfieldslist.Add((j, cell.Text.ToString(), ""));
//cell.ForeColor = System.Drawing.Color.Red;
}
}
if (j == e.Row.Cells.Count -1)
{
//var SortedPreisfieldList = Preisfieldslist.OrderBy(r => r.Preis);
var LowerstPreis = Preisfieldslist.Min(r => r.Preis);
var HiegerstPreis = Preisfieldslist.Max(r => r.Preis);
for (int c = 0; c < Preisfieldslist.Count; c++)
{
if (LowerstPreis == Preisfieldslist[c].Preis)
{
int n = Preisfieldslist[c].cellNr;
e.Row.Cells[n].ForeColor = System.Drawing.Color.Green;
}
if (HiegerstPreis == Preisfieldslist[c].Preis)
{
int n = Preisfieldslist[c].cellNr;
e.Row.Cells[n].ForeColor = System.Drawing.Color.Red;
}
}
}
}
}
} // ende for (int i = 0; i < totalRow +1 ; i++)
}
I have a special thing to solve and can find a solution.
The Datagrid is bound to SQL query and has dynamic inner Join that is detectable all-time changing. The user can select any imported Data to show differences between up to 10 databases.
The Labelname of columns is EPreis and BPreis.
Now I need to find all EPreis and all BPreis eggs 5xBPreis 5xEPreis on Row.
Funktion1
BPreis cheapest Background color = green
Secend Preis Background Color = Yello
3...... 10.
The same on EPreis.
C#
protected void run_Click(object sender, EventArgs e)
{
SqlDataAdapter adp1 = new SqlDataAdapter(getSearch, con);
DataTable dt1 = new DataTable();
adp1.Fill(dt1);
mergeresult.DataSource = dt1;
mergeresult.DataBind();
}
protected void mergeresult_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex >= 0)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
for (int i = 0; i < e.Row.count - 1; i++)
{
for (int cellIndex = 0; cellIndex < Row.Cells.Count; cellIndex++)
{
if ((Label)e.row.cell.cellindex == "EPreis")
{
//? Howto find all PReis and EPreis in row.count
// is posible to put cell[x] and cell.text in array
// and at end of row sorting array 1 to x to colering
// the cell.
// Later to expand funktion Tolltip or mous over to show %
// Diverent to cheeperst
}
}
}
}
}
}
I found a solution but it still doesn't work properly.
The highest and lowest prices are sometimes reversed.
if (e.Row.RowIndex >= 0)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int totalRow = mergeresult.Rows.Count;
int totalColumns = mergeresult.Columns.Count;
for (int i = 0; i < totalRow + 1; i++)
{
//int anzahl = (int)ViewState["Anzahlfrom"];
//string[] NumOfPreisfields = new string[anzahl];
var Preisfields = new List<string>();
var Preisfieldslist = new List<(int cellNr, string Preis, string color)>();
for (int j = 0; j < e.Row.Cells.Count; j++)
{
var SearchColumnName = "EK";
DataControlFieldCell cell = (DataControlFieldCell)e.Row.Cells[j];
if (cell.ContainingField is BoundField)
{
if (((BoundField)cell.ContainingField).DataField.Contains(SearchColumnName))
{
Preisfields.Add(j.ToString());
Preisfieldslist.Add((j, cell.Text.ToString(), ""));
//cell.ForeColor = System.Drawing.Color.Red;
}
}
if (j == e.Row.Cells.Count -1)
{
//var SortedPreisfieldList = Preisfieldslist.OrderBy(r => r.Preis);
var LowerstPreis = Preisfieldslist.Min(r => r.Preis);
var HiegerstPreis = Preisfieldslist.Max(r => r.Preis);
for (int c = 0; c < Preisfieldslist.Count; c++)
{
if (LowerstPreis == Preisfieldslist[c].Preis)
{
int n = Preisfieldslist[c].cellNr;
e.Row.Cells[n].ForeColor = System.Drawing.Color.Green;
}
if (HiegerstPreis == Preisfieldslist[c].Preis)
{
int n = Preisfieldslist[c].cellNr;
e.Row.Cells[n].ForeColor = System.Drawing.Color.Red;
}
}
}
}
}
} // ende for (int i = 0; i < totalRow +1 ; i++)
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论