好吧,现在这太令人沮丧了。我有一个 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>
它只是没有将gridview放入我的var中!即使我只是检查 grid.rows.length 它也不理解行。我正在查看其他代码示例,他们做我正在做的同样的事情,他们说它工作正常。我 100% 确定它正在选择我的 GridView。到底是怎么回事?
编辑:这是它的 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);
}