gpt4 book ai didi

c# - 通过 C# 呈现包含数据的表格的动态 html 的意外行为

转载 作者:行者123 更新时间:2023-11-29 15:44:51 28 4
gpt4 key购买 nike

我遇到了一个不熟悉的功能问题。我认为它与循环范围和呈现页面时的服务器端代码操作/操作有关。

假设我想重复一个表格行 - 每个表格行都有一个文本输入,行和它们的文本框根据数据库“绑定(bind)”数据的内容呈现值。

一切正常,直到添加更多要求 - READONLY 属性和事件键(javascript 小型验证任务)。

否则它确实有效,通过我用字符串格式“注入(inject)”的两个单独的字符串交替行,条件是行数是奇数还是偶数,然后我尝试过滤一些列以将按键事件绑定(bind)到js 函数和另一个属性作为字符串。

如果字符串为空,则元素“声明”的结尾部分将为空如果满足条件,则为该字符串分配值“ReadOnly”,并为 js 字符串分配按键事件“调用功能代码”。

这是代码。情况很奇怪,因为 style 属性、当前列的信息、列名,一切都按预期运行,但那两个 READONLY 属性和 event 键(javascript 小型验证任务)没有。

渲染动态表格代码

这是前面的代码,后面用的最多的是c#代码(尽可能少的客户端代码)

`ControlsInteraction.WithTable.Design()`

`ControlsInteraction.WithTable.ExtractData()`

正在处理列名称和值的呈现和翻译的动态函数

int count = 0;
bool TblOk = DebugTests.Sesseion.SeSn.Raised(DebugTests.Flag.HT_DB_CPA_Table_init_Complete);
if (TblOk)
{
string TextBxRendr = "";//holds Renderd <TD> base String-code

string AltrnatBgColor;
string NoAttribute = "";
string Js_NumericKprss = "onkeypress=\"return onlN(event)\""
string ReadOnly = "READONLY";
var TimesCol = ALLTablesDataSet.Tables[Tbl1.TableName].Columns;
string DtrawTbl1 = Tbl1.TableName;
ControlsInteraction.WithTable.Design Tbldz =
new ControlsInteraction.WithTable.Design();

ControlsInteraction.WithTable.ExtractData DtExtrct =
new ControlsInteraction.WithTable.ExtractData();

foreach (System.Data.DataRow TimesRow in ALLTablesSet.Tables[DtrawTbl].Rows)
{

AltrnatBgColor= Tbldz.RowsBGColorAlternate(RDE.DataRowToInt(TimesRow, "RecordNum"),true);
altBgColOnly = Tbldz.RowsBGColorAlternate(RDE.DataRowToInt(TimesRow, "RecordNum"), false);
Response.Write(string.Format("<tr {0}>",AltrnatBgColor));

for (int i = 0; i < TimesRow.ItemArray.Length; i++)
{
if (i != (TimesRow.ItemArray.Length - 1))
{


Js_NumericKprss = "onkeypress=\"return onlN(event)\"";

//asking for: current row will Not be read only via its name
if (DtExtrct.CurrRowIs(TimesRow, MyDBSchema.DBs_Cols.TblCPAReport.Comments, DtExtrct.DataRowToInt(TimesRow, "RecordNum")))
Js_NumericKprss = NoAttribute; // same goes with the other manipulation i've needed to implement on each column
TextBxRendr = string.Format(
"<td><input type='text' id=\"{0}_{1}\" value=\"{2} \" style=\"width:50px;{3} border:none; \" class=\"RepTblDataTDs\" {4} {5} \\></td>",
TimesCol[i], TimesRow["RecordNum"], TimesRow[i], AltrnatBgColor,Js_NumericKprss,ReadOnly
);

}

else
{
TextBxRendr = string.Format(
"<td><input type='image' id=\"{0}_{1}\" src=\"images/Save.png\" style=\"width:25px;{2}\" style=\"width:25px\" onclick=\"UbpdateTblCPA(this, {1});\" /></td>",
"img",i + 1, AltrnatBgColor
);
}


Response.Write(TextBxRendr);
count++;
}

}
}

正确注入(inject)只读部分READONLY属性,以及事件Key——(javascript小验证任务)

全部或无功能

我做错了什么?

最佳答案

最终回答我自己的问题是

...好吧一切,包括@Patrics 评论是错误的

我只能说要特别注意:如何使用 DataTable DataRow、DataTable DataColumns以及 for 和 foreach 变量范围的关系在每一行上使用你的 visual sudio 调试器来检查你的代码值

我没有时间重命名变量但是如果你需要做一个动态的html table out of a DB table 这是方法

   foreach (System.Data.DataRow TimesRow in ALLTablesSet.Tables[DrawTbl].Rows)
{
recordNum = RDE.DataRowToInt(TimesRow, "RecordNum");
AltBgCol = Tbldz.RowsBGColorAlternate(RDE.DataRowToInt(TimesRow, "RecordNum"), true);
altBgColOnly = Tbldz.RowsBGColorAlternate(RDE.DataRowToInt(TimesRow, "RecordNum"), false);
Response.Write(string.Format("<tr {0}>", AltBgCol));
for (int i = 0; i < TimesRow.ItemArray.Length; i++)
{


if (i != (TimesRow.ItemArray.Length - 1))
{
Js_NumericKprss = "onkeypress=\"return onlN(event)\""; ReadOnly = "";
if (RDE.CurrRowIs(TimesRow, HentalDBSchema.HTDB_Cols.TblTimeCPAReport.Comments, i))
{
Js_NumericKprss = ""; ReadOnly = "";
}

else if (RDE.CurrRowIs(TimesRow, HentalDBSchema.HTDB_Cols.TblTimeCPAReport.Fines, i)
|| RDE.CurrRowIs(TimesRow, MyDBSchema.DBs_Cols.TblCPAReport.PhoneExpences, i)
|| RDE.CurrRowIs(TimesRow, MyDBSchema.DBs_Cols.TblCPAReport.SalaryPerDay, i)
|| RDE.CurrRowIs(TimesRow, MyDBSchema.DBs_Cols.TblCPAReport.SalaryPerMonth, i)
|| RDE.CurrRowIs(TimesRow, MyDBSchema.DBs_Cols.TblCPAReport.TotalGrossWages, i)
|| RDE.CurrRowIs(TimesRow, MyDBSchema.DBs_Cols.TblCPAReport.TravelFee, i))
{
ReadOnly = "";
Js_NumericKprss = "onkeypress=\"return onlN(event)\"";
}
else
ReadOnly = "READONLY";

TxtRndr = string.Format("<td><input type='text' id=\"{0}_{1}\" value=\"{2} \" style=\"width:50px;{3} border:none; \" class=\"RepTblDataTDs\" {5} {6} \\></td>{4}", TimesCol[i], TimesRow["RecordNum"], TimesRow[i], altBgColOnly, Environment.NewLine + "\t\t\t", Js_NumericKprss, ReadOnly);
}

else
{
TxtRndr = string.Format("<td><input type='image' id=\"{0}_{1}\" src=\"images/Save.png\" style=\"width:25px;{3}\" style=\"width:25px\" onclick=\"UbpdateTblCPA(this, {1});\" /></td>{4}", "imgBut", i + 1, TimesRow[i], altBgColOnly, Environment.NewLine + "\t\t\t");
}


Response.Write(TxtRndr);




count++;
}

}

我正在添加我所做的所有研究,以便更容易地提取 data 以及我研究过的更多方法,所以如果你喜欢使用它,请随时...

    public class ControlsInteraction
{
public class WithDDL
{
public class GetSelVal
{
public string AsString(DropDownList DDLToCollectValusFrom)
{

return DDLToCollectValusFrom.SelectedValue;
}
public int AsInt(DropDownList DDLToCollectValusFrom)
{
if(DDLToCollectValusFrom.SelectedValue != null)
return Convert.ToInt32(DDLToCollectValusFrom.SelectedValue);
return 666;
}
}
public List<string> GetListItems_Values(DropDownList DDLToCollectValusFrom)
{
List<string> LST_DDLValues = new List<string>();
foreach (ListItem item in DDLToCollectValusFrom.Items)
{
LST_DDLValues.Add(item.Value);


}
return LST_DDLValues;
}
public List<string> GetListItems_Text(DropDownList DDLToCollectTextFrom)
{
List<string> LST_DDLTEXT = new List<string>();
foreach (ListItem item in DDLToCollectTextFrom.Items)
{
LST_DDLTEXT.Add(item.Text);


}
return LST_DDLTEXT;
}
}
public static class WithPlcHldr
{
public static void AddCtrl(PlaceHolder PlcHldrID, Control CntrID)
{
PlcHldrID.Controls.Add(CntrID);
}
}
public class WithTable
{
public class Design
{
public string RowsBGColorAlternate(int RowCounter, bool AddWithStyleAsStandAlone = false)
{
string BgCol = ""; bool bgclaltrnator;
if (RowCounter > 0)
{
RowCounter++;
bgclaltrnator = (RowCounter % 2) == 0;
if (bgclaltrnator)
BgCol = "#70878F";
else BgCol = "#E6E6B8";
}
if (AddWithStyleAsStandAlone)
return string.Format("style=\"background-color:{0};\"", BgCol);
return string.Format("background-color:{0};", BgCol);
}
}
public class ExtractData
{
public string ColumnValueFromCurrRow(DataRow DtRow, string RequestedColName)
{
return "";
}
public string DataRows_ColumnToString(DataRow Data_RowToActOn, string keyColName)
{
var tmp = Data_RowToActOn[keyColName];
return Data_RowToActOn[keyColName].ToString();

}
public int DataRowToInt(DataRow Data_RowToActOn, string keyColName)
{
string tmp = Data_RowToActOn[keyColName].ToString();
return Convert.ToInt32(tmp);

}
public bool CurrColumnIs(DataColumn Data_RowToQuestion, string ColumnName)
{
string tmp = Data_RowToQuestion.ToString();
return tmp == ColumnName;
}
public bool CurrRowIs(DataRow Data_RowToQuestion, string RowName, int CurrIndex)
{
string ColsName = Data_RowToQuestion.Table.Columns[CurrIndex].ToString();
return ColsName == RowName;
//this is curent value - by index

//string currentColumn = Data_RowToQuestion.ItemArray[CurrIndex].ToString();

}
}

}
}

关于c# - 通过 C# 呈现包含数据的表格的动态 html 的意外行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13221925/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com