私は aspx.cs コードでテーブルを作成します:
protected void buildTable()
{
ClientScriptManager cs = Page.ClientScript;
List<Account> accountList = dbs.getAllAccounts(userId);
string userName = dbs.getUserName(userId);
Table accountTable = new Table();//creating the table
accountTable.CssClass = "tsc_table_s4";
TableHeaderRow headerRow = new TableHeaderRow();//creating header row
TableHeaderCell th1 = new TableHeaderCell();
th1.Scope = TableHeaderScope.Column;
th1.Text = "Account Name";
TableHeaderCell hc1 = new TableHeaderCell();
th1.Text = "Account Name";
TableHeaderCell th2 = new TableHeaderCell();
th2.Text = "Owner";
TableHeaderCell th3 = new TableHeaderCell();
th3.Text = "Website";
TableHeaderCell th4 = new TableHeaderCell();
th4.Text = "Phone";
TableHeaderCell th5 = new TableHeaderCell();
th5.Text = "Industry";
TableHeaderCell th6 = new TableHeaderCell();
th6.Text = "Website";
TableHeaderCell th7 = new TableHeaderCell();
th7.Text = "Adress Details";
TableHeaderCell th8 = new TableHeaderCell();
th8.Text = "Annual Revenue";
TableHeaderCell th9 = new TableHeaderCell();
th9.Text = "Comments";
headerRow.Cells.Add(th1);
headerRow.Cells.Add(th2);
headerRow.Cells.Add(th3);
headerRow.Cells.Add(th4);
headerRow.Cells.Add(th5);
headerRow.Cells.Add(th6);
headerRow.Cells.Add(th7);
headerRow.Cells.Add(th8);
headerRow.Cells.Add(th9);
accountTable.Rows.Add(headerRow);
for (int i = 0; i < accountList.Count; i++)
{
TableRow tr = new TableRow();
tr.Attributes.Add("onclick", cs.GetPostBackEventReference(this, tr.ID.ToString()));
for (int j = 0; j < headerRow.Cells.Count; j++)
{
TableCell td = new TableCell();
//TableCell tdValidator = new TableCell();
if (j == 0)
td.Text = accountList[i].AccountName;
else if (j == 1)
td.Text = userName;
else if (j == 2)
td.Text = accountList[i].Website;
else if (j == 3)
td.Text = accountList[i].Phone;
else if (j == 4)
td.Text = dbs.getIndustryName(accountList[i].Industry);
else if (j == 5)
td.Text = accountList[i].Website;
else if (j == 6)
td.Text = accountList[i].Address;
else if (j == 7)
td.Text = Convert.ToString(accountList[i].AnnualRevenue);
else if (j == 8)
td.Text = accountList[i].Description;
//td.Controls.Add(b);
tr.Controls.Add(td);
}
accountTable.Controls.Add(tr);
}
accountTable.Style["width"] = "inherit";
tableDiv.Controls.Add(accountTable);
}
ここにaspxのコードがあります:
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div class="tsc_gradient2" align="center">
<h4>
Accounts</h4>
</div>
<div id="tableDiv" Runat="server" style="width:inherit;">
</div>
私は2つの問題を抱えています.
- テーブルの行をクリックすると、この行から情報を取得できるという考えで、イベント onRowClick を作成しようとしています。
これを解決する方法はありますか?