jquery - 查找嵌套的Gridview和控件 [英] jquery - Finding nested Gridview and controls in it
问题描述
需要帮助查找嵌套的Gridview和其中存在的控件,例如标签
使用jquery
我在做下面的计算中是jQuery代码。 ()函数(){
//父代gridview $ b的硬编码控件ID $ b $ $(#<%= gvSupplierList.ClientID%> $ b $(this).find('span [id $ =gvSupplierList_lblsizeofopt_0]')。text('0.01');
//子代的嵌套gridview控制ID
$(#gvSupplierList_gvCustomerList_0> tbody> tr)。each(function(){
//子代/嵌套控件的硬编码控件ID $ b $(this).find '输入[id $ =gvSupplierList_gvCustomerList_0_txtsizeofopt_0]').val();
});
});
预先致谢。
您需要使用FindControl来浏览Control Tree,并在Child GridView的行中找到正确的TextBox。
< asp:GridView ID =GridViewParentrunat =serverOnRowDataBound =GridView1_RowDataBound>
<列>
< asp:TemplateField>
< ItemTemplate>
< asp:GridView ID =GridViewChildrunat =server>
<列>
< asp:TemplateField>
< ItemTemplate>
< asp:TextBox ID =TextBox1runat =server>< / asp:TextBox>
< / ItemTemplate>
< / asp:TemplateField>
< /列>
< / asp:GridView>
< / ItemTemplate>
< / asp:TemplateField>
< /列>
< / asp:GridView>
< script type =text / javascript>
$(#<%=((GridView)GridViewParent.Rows [1] .FindControl(GridViewChild)).Rows [2] .FindControl(TextBox1).ClientID%>)。 val(TextBox is found!);
< / script>
在这段代码中,子代的第1行和第2行的TextBox位于文本集。
或者,如果您知道jQUewry中的两行,您也可以这样做
< script type =text / javascript>
var parentRow = 3;
var childRow = 5;
$('#<%= GridViewParent.ClientID%> table')。each(function(index,element){
if(index == parentRow){
$('#'+ element.id +'input [type =text]')。each(function(indexNested,elementNested){
if(indexNested == childRow){
$(这个).val(TextBox is found!)
}
});
}
});
< / script>
Need help in finding nested Gridview and controls present in it for e.g. label using jquery
I am in middle of doing calculations below is the jquery code.
$("#<%=gvSupplierList.ClientID %>").each(function () {
//hardcoded control id of parent gridview
$(this).find('span[id$="gvSupplierList_lblsizeofopt_0"]').text('0.01');
//hardcoded control id of child/nested gridview
$("#gvSupplierList_gvCustomerList_0 > tbody > tr").each(function () {
//hardcoded control id of child/nested control
$(this).find('input[id$="gvSupplierList_gvCustomerList_0_txtsizeofopt_0"]').val();
});
});
Thanks in advance.
You need to use FindControl to navigate up the Control Tree and locate the correct TextBox in the Rows of the Child GridView.
<asp:GridView ID="GridViewParent" runat="server" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:GridView ID="GridViewChild" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<script type="text/javascript">
$("#<%= ((GridView)GridViewParent.Rows[1].FindControl("GridViewChild")).Rows[2].FindControl("TextBox1").ClientID %>").val("TextBox is found!");
</script>
In this snippet the TextBox in row 1 of the parent and row 2 of the child is located and the text set.
Or if you know both the rows in jQUewry you can also do this
<script type="text/javascript">
var parentRow = 3;
var childRow = 5;
$('#<%= GridViewParent.ClientID %> table').each(function (index, element) {
if (index == parentRow) {
$('#' + element.id + ' input[type="text"]').each(function (indexNested, elementNested) {
if (indexNested == childRow) {
$(this).val("TextBox is found!")
}
});
}
});
</script>
这篇关于jquery - 查找嵌套的Gridview和控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!