无法将我的GridView放入我的javascript变量中

时间:2012-07-09 22:25:41

标签: c# jquery asp.net

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

2 个答案:

答案 0 :(得分:1)

请更改以下行

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

这样

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

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

答案 1 :(得分:0)

变化:

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

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

此外,我认为您正在尝试从客户端访问服务器端属性,这将无法正常工作。

相关问题