如何动态更改gridview ID [英] how to change gridview ID dynamically

查看:148
本文介绍了如何动态更改gridview ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想动态调用gridview id并绑定数据源



i有10个gridview的名字就像gv1,gv2,gv3 --- gv10



实际上在我的员工日期,每个部门都没有员工,但不超过10,

,当我选择部门我想显示如下



EmployeeName1(Header)EmployeeName2(Header)EmployeeName3(Header)

地址地址

手机没有手机没有手机否

性别性别性别

Desgnation Desgnation Desgnation









一些有1名员工的部门也应该显示员工的详细信息






谢谢...

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...

推荐答案

这正是你应该如何实现你的网格,但首先我想提醒你使用单个页面上的多个网格视图是个坏主意。当你需要动态更新它们时情况变得更糟。



所以这就是你应该怎么做的:



1)将您的员工网格放在更新面板中。

2)您需要将gridview的客户端ID发送到javascript。这可以按如下方式完成 -





var grid1Id ='& lt;%= grid1.ClientID%& gt;' ;

var grid2Id ='& lt;%= grid2.ClientID%& gt;';





3)您需要将部门网格更改事件与更新员工网格更新面板的功能绑定。为此,您可以将行数据绑定事件中的自定义属性添加到输入,然后使用基于属性选择器的jQuery查找该输入。


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)在更改事件功能,更新更新面板:



函数changeEvent()

{

__doPostBack(grid2Id) ;

}



尝试以上操作,看看它是怎么回事。
('#' + 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.


这篇关于如何动态更改gridview ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆