Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I want to call gridview id dynamically and to bind datasources

i have 10 gridview's names are like gv1,gv2,gv3---gv10

actually in my employee date each department have no.of employees but not more than the 10,
when i am select department i wanto display like below

EmployeeName1(Header) EmployeeName2(Header) EmployeeName3(Header)
Address Address Address
Mobile no Mobile no Mobile no
Gender Gender Gender
Desgnation Desgnation Desgnation
"""""" """""" """"""
"""""" """""" """"""
"""""" """""" """"""

some departments having 1 employee also it shoud be display that employee details also



thanks...
Posted
Updated 13-Jan-16 18:19pm
v2
Comments
DamithSL 9-Jan-16 4:40am    
what have you tried so far?
Maciej Los 9-Jan-16 5:02am    
Sorry, what do you mean by "call gridview id dynamically"?
Ashwini Dhale 9-Jan-16 5:25am    
create grid view object in a loop and assign the gridview.id=loop number
[no name] 9-Jan-16 9:19am    
Please elaborate when you say "call gridview id dynamically and to bind datasources"
Parazival 14-Jan-16 0:31am    
thanks for replay , i'll Update my questuion.

1 solution

This is exactly how you should implement your grids, but first I would like to remind you that using multiple grid views on a single page is a bad idea. Things get even worse when you need to dynamically update them.

So here is how you should do it:

1) Put your employee grid in an update panel.
2) You need to send your gridview's client id to javascript. This can be done as follows -


var grid1Id = '<%= grid1.ClientID %>';
var grid2Id = '<%= grid2.ClientID %>';


3) You need to bind the department grid change event with a function which will update the update panel of the employee grid. For this purpose you can add a custom attribute from the row data bound event to an input and then find that input using jQuery basd on the attribute selector.

$('#' + grid1Id).find('[ChangeInput="true"]').click(changeEvent);

4) In the change event function, update the update panel:

function changeEvent()
{
__doPostBack(grid2Id);
}

Try the above and see how it goes.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900