亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

ScriptManager.RegisterStartupScript 僅在 foreach

ScriptManager.RegisterStartupScript 僅在 foreach

C#
慕森卡 2022-06-18 17:37:23
我有一個數據表,其中包含我從數據庫中獲得的記錄。當頁面加載時,我想瀏覽每條記錄并將值提交給 JavaScript 函數,該函數將它們顯示到頁面上,但是,它僅適用于表中的第一條記錄。如果有人有辦法解決這個問題或有更好的方法來做我想做的事情,我們將不勝感激。我背后的代碼:foreach(DataRow row in tlds.Rows) {    TLDid = Convert.ToInt32(row["tldID"]);    tldName = row["tldName"].ToString();    date = row["releaseDate"].ToString();    price = Convert.ToDouble(row["price"]);    tags = row["tags"].ToString();    ScriptManager.RegisterStartupScript(this, this.GetType(), "tld", "addTLD('" + TLDid + "','" + tldName + "','" + date + "','" + price + "')", true);} 我的js函數:function addTLD(tldID, tldName, releaseDate, price) {    $('<tr><td>' + tldName + '</td><td>' + releaseDate + '</td><td>' + price + '</tr>').insertAfter('tr');}
查看完整描述

1 回答

?
紅顏莎娜

TA貢獻1842條經驗 獲得超13個贊

您可以使用 ASP.NET 服務器端表格控件,然后動態添加行并為每一行添加所需的單元格,如下面的代碼


ASPX


<asp:Table ID="myTable" runat="server" Width="100%"> 

</asp:Table>

ASPX.CS


    foreach (DataRow row in tlds.Rows)

                {

                    date = row["releaseDate"].ToString();

                    price = Convert.ToDouble(row["price"]);

                    tags = row["tags"].ToString();


                     TableRow row = new TableRow();


                     TableCell TLIdCell= new TableCell();

                     TLIdCell.Text = Convert.ToInt32(row["tldID"]);

                     row.Cells.Add(TLIdCell);


                      TableCell tldNameCell = new TableCell();

                      tldNameCell .Text = Convert.ToString(row["tldName"]);

                      row.Cells.Add(tldNameCell);


                     //Similarly add code for date, price and tags cells


                      // Finally add row to table rows collection

                      myTable.Rows.Add(row);

                } 


查看完整回答
反對 回復 2022-06-18
  • 1 回答
  • 0 關注
  • 136 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號