asp.net - How to reset ListBox.Rows property to default (without hard coding the default value) -


i have asp.net listbox on page, , postbacks occur, change items in list. if there >= 10 items in list, set rows property = 10. if there less 10 items, i'd set rows whatever default value rows.

i see examining reflected code default value 4, i'd rather not hard code 4 in code , instead somehow reset default.

is there way this?

you can fetch default value during page's init phase. documentation:

in stage of page's life cycle, declared server controls on page initialized default state; however, view state of each control not yet populated.

so can like:

private int _defaultrows;  protected void page_init(object sender, eventargs e) {     _defaultrows = yourlistbox.rows; }  protected void page_prerender(object sender, eventargs e) {     if (yourlistbox.items.count >= 10) {         yourlistbox.rows = 10;     } else {         yourlistbox.rows = _defaultrows;     } } 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -