3

機能に関してよくわからない問題が発生しています。ループの範囲と、ページをレンダリングするときのサーバー側のコード操作/操作に関係があると思います。

テーブル行を繰​​り返したいとします-それぞれがテキスト入力をホストし、行とそのテキストボックスは、データベースの「バインドされた」データの内容に応じた値でレンダリングされます。

さらに要件が追加されるまで、すべてが完全に機能します - READONLY Attribute And event Key (javascript small validation task)。

それ以外の場合は機能し、行数が奇数対偶数の場合に文字列形式で「注入」する2つの分離された文字列を介して行を交互に配置し、いくつかの列をフィルタリングしてキープレスイベントをjs関数にバインドしようとしました文字列としての別の属性。

文字列が空の場合、条件が満たされた場合、要素「宣言」の最後の部分は空になり、その文字列には値「ReadOnly」が割り当てられ、js文字列には「関数コードの呼び出し」キープレスイベントが割り当てられます。

これがコードです。style属性、現在の列の情報、列名、すべてが期待どおりに機能するため、状況は奇妙ですが、これらの2つの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++;
                 }

        }
}

READONLY 属性と読み取り専用部分、およびイベント Key - (javascript 小さな検証タスク) が正しく挿入されている

すべてまたはまったく機能しない

私は何を間違っていますか?

4

1 に答える 1

1

自分の質問に答えると答えは

...まあ、@Patrics コメントを含むすべてが間違っていました

私はただ注意を払うと言うことができます:DataTable DataRow、DataTable DataColumns、および for および foreach 変数スコープの関係を操作する方法は、すべての行でビジュアル sudio デバッガーを使用してコード値を確認します

変数の名前を変更する時間はありませんでしたが、DB テーブルから動的な html テーブルを作成する必要がある場合は、これが方法です

   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();

                }
            }

        }
    }
于 2012-11-05T15:31:07.190 に答える