开发者

Error in getting row count using javascript

I am trying to get the row count of grid view using javascript. Javascript is called but some how I am not getting row count. This is the code for my javascript

<script language="javascript" type="text/javascript">
function CheckSites() {

    var Grid = document.getElementByID(<%=grdSiteInformation.ClientID%>);
    var row = Grid.rows.length;
    alert(grid);
if(length=0)
    alert('Enter atleast one site');
    }
</script>

This is how I am calling that function...

<asp:Button ID="btnAdd" runat="server" Text="Save" OnClick="btnAdd_Click" OnClientClick="CheckSites()"/>

This is the definition of my gridview

<asp:GridView ID="grdSiteInformation" runat="server" AutoGenerateColumns="False"
                        OnRowCommand="grdSiteInformation_RowCommand">
                        <Columns>
                            <asp:BoundField DataField="TableRowIndex" HeaderText="Sr.No" />
                            <asp:BoundField DataField="SiteID" HeaderText="SiteID" />
                            <asp:BoundField DataField="POrderID" HeaderText="POrderID" />
                            <asp:BoundField DataField="SiteName" HeaderText=开发者_开发知识库"SiteName" />
                            <asp:BoundField DataField="Location" HeaderText="Location" />
                            <asp:BoundField DataField="SiteAddress" HeaderText="SiteAddress" />
                            <asp:BoundField DataField="Cluster" HeaderText="Cluster" />
                            <asp:BoundField DataField="SubVendorName" HeaderText="SubVendorName" />
                            <asp:TemplateField>
                                <ItemTemplate>
                                    <asp:Button ID="btnEdit" runat="server" CommandArgument='<%# Eval("SiteID") %>' CommandName="Edt"
                                        Text="Edit" />
                                </ItemTemplate>
                                <HeaderTemplate>
                                    Edit
                                </HeaderTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>

Please guide me where/what I am making mistake mistake...

Thanks


If you are using Asp.Net's GridView and you just want row count then you can change your js function as:

function CheckSites() 
{    
    var row = <%=grdSiteInformation.Rows.Count %>    
    if(row=0)
    alert('Enter at least one site');
}


Try

var rowCount = document.getElementById('<%=grdSiteInformation.ClientID%>')
       .getElementsByTagName("TR").length;
alert(rowCount); 

Edit

Try jQuery

var totalRows = $("#<%=GridView1.ClientID %> tr").length;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜