さて、これは今とてもイライラしています。9列のGridViewがあります。そのうちの3つを表示していますが、行をクリックすると他の6つを表示する別のテーブルが必要です。選択した行をクリックしたときに新しいテーブルに配置するようにjavascript関数を設定しています...それが機能しないことを除いて!
<script type="text/javascript">
var table = $('<table></table>');
var grid = document.getElementById('<%=BillabilityView.ID %>'); // here it is inputting gridview.
$(document).ready(function () {
$(".tbl tr:has(td)").css({ background: "ffffff" }).click(
function () {
var row = $('<tr></tr>').addClass('bar').text(grid.rows[$(this).index()]); // here it is saying 'unable to get the value of property rows'
table.append(row);
$('#please').append(table);
}
);
});
</script>
グリッドビューを私の変数に入れていないだけです!grid.rows.lengthをチェックするだけでも、行を理解できません。私は他のコードサンプルを見ています、そしてそれらは私がしているのと同じことをします、そして彼らはそれがうまくいくと言います。私はそれが私のGridViewを選択していると100%確信しています。何が起こっている?
編集:これはそれのasp.net側です:
<asp:GridView ID="BillabilityView" BackColor="White" runat="server" AutoGenerateColumns="false" CssClass="tbl">
<columns>
<asp:boundfield datafield="UserName" headertext="User Name" />
<asp:boundfield datafield="UserID" headertext="User ID" />
<asp:boundfield datafield="HrsTLB" headertext="Billable Hours" />
<asp:boundfield datafield="HrsTLNB" headertext="Nonbillable Hours" />
<asp:boundfield datafield="HrsTL" headertext="Total Hours" />
<asp:boundfield datafield="HrsExp" headertext="Expected Hours" />
<asp:boundfield datafield="Billability" headertext="Billability" />
</columns>
</asp:GridView>
<div id = "please">
</div>
キックのためにC#をスローすることもできます
BillabilityView.DataSource = dataList.retBillability();
BillabilityView.DataBind();
BillabilityView.RowDataBound += new GridViewRowEventHandler(BillabilityView_RowDataBound);
void BillabilityView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.BackColor = Color.FromName("#ebebeb");
}
//e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink
// (this.BillabilityView, "Select$" + e.Row.RowIndex);
}