0

好吧,现在这太令人沮丧了。我有一个 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);
    }
4

2 回答 2

1

请更改以下行

var grid = document.getElementById('<%=BillabilityView.ID %>');
$(document).ready(function () {

至此

$(document).ready(function () {
  var grid = $("#BillabilityView");

PS:为了保持一致性,请使用 jquery 来 getElementById 而不是 document.getElementById

于 2012-07-09T22:48:19.207 回答
0

改变:

var grid = document.getElementById('<%=BillabilityView.ID %>');

var grid = document.getElementById('<%=BillabilityView.ClientID %>');

另外,我认为您正在尝试从客户端访问服务器端属性,这是行不通的。

于 2012-07-09T22:40:43.587 回答