Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Existing rows from dataGrid

Status
Not open for further replies.

shangrilla

Programmer
Nov 21, 2001
360
US
I am using a dataset to populate a grid. Then using some client side javascript I decide what is the maximum # of rows that can be added to a grid.

I declare a global javascript variable 'cnt' and initialize it to 0. Say the max rows that can be added is 5. If there are no rows in the grid when it is loaded, this will work just fine. What if there are 2 rows already present in grid when it is loaded.

So my question is how can I initialize cnt to 2(rows already present in the grid before insert).

Thanks
 
You can add a label control to your page, and initialize it like this:

myLabel.text = &quot;<script language=javascript>cnt=2;</script>&quot;

set the enableViewState property = false, so that the value of the label doesn't persist over a postback, and therefore reset the value when the page reloads.

If you run into any issues (like the label gets rendered before you declare your cnt variable -- causing a null reference error), then just abstract the logic into a function, and call the function onLoad for your <body>

-paul
penny1.gif
penny1.gif

The answer to getting answered -- faq855-2992
 
Hi Paul:

Thanks for your reply. I do not need to initialize cnt = 2. cnt can be any number of rows already showing in the datagrid when the page is loaded.
So my question is how to get the number of rows in the grid, when the page is loaded.

Sorry if I didn't make myself clear earlier.
 
You can get the numbers of rows present by invoking the .count property on the datagrid's item collection

penny1.gif
penny1.gif

The answer to getting answered -- faq855-2992
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top