子GridView失去对按钮单击的关注 [英] Child gridview losing focus on button click
问题描述
我已经完成了以下方案,我有一个网格视图,该网格视图具有另一个网格视图作为该网格视图的Item模板.最初,我绑定了一个单选按钮和数据库中的必填字段.当用户选择单选按钮时,我会在另一个网格中显示相应的详细信息.此网格视图具有一些带有复选框的必填字段.当我选中一个复选框并单击网格视图外的按钮时,我无法执行所编写的要求
I have done a scenario as follows, I am having a grid view which is having another grid view as Item template of that grid view. Initially I binded a radio button and the required fields from the database. When ever user selects a radio button I will show the corresponding details in another gridi vew. This grid view has some necessary fields with check boxes. When I select a check box and click on a button out side the grid view I am unable to execute the required that was written
<asp:Panel CssClass="grid" ID="pnlCust" runat="server">
<asp:GridView ID="gvCustomers" AutoGenerateColumns="False" DataKeyNames="EmpID" runat="server"
ShowHeader="true" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None"
BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Vertical">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<%--<asp:Image ID="imgCollapsible" CssClass="first" ImageUrl="~/Assets/img/plus.png"
Style="margin-right: 5px;" runat="server" /><span class="header">
<%#Eval("EmpID")%>
:
<%#Eval("empname")%>--%>
<asp:RadioButton ID="rdbtn" runat="server" onclick="RadioCheck(this);" OnCheckedChanged="radio_changed"
Text='<%# Bind("EmpID") %>' AutoPostBack="true"></asp:RadioButton>
<asp:GridView AutoGenerateColumns="false" CssClass="grid" ID="gvOrders" runat="server"
PageSize="1" ShowHeader="true" EnableViewState="false" DataKeyNames="EmpID" OnPageIndexChanging="gvOrders_PageIndexChanging">
<RowStyle CssClass="row" />
<AlternatingRowStyle CssClass="altrow" />
<Columns>
<asp:BoundField HeaderText="Employee Id" DataField="EmpID">
<ItemStyle HorizontalAlign="Center" Width="100px" />
</asp:BoundField>
<asp:TemplateField ItemStyle-CssClass="rownum">
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-BackColor="#EFF1F1" ItemStyle-HorizontalAlign="Center"
ItemStyle-Height="25" HeaderStyle-Width="50" ItemStyle-Width="50">
<HeaderTemplate>
<input id="chkBoxAll" type="checkbox" onclick="checkAllBoxes()" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkBoxChild" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="PayPeriodNumber" HeaderText="PayPeriod" HeaderStyle-BackColor="#EFF1F1"
ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="80" ItemStyle-Width="80">
</asp:BoundField>
<asp:BoundField DataField="PayRollYear" HeaderText="Payroll Year" HeaderStyle-BackColor="#EFF1F1"
ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="100" ItemStyle-Width="100">
</asp:BoundField>
<asp:BoundField DataField="PaymentDate" HeaderText="Payment Date" HeaderStyle-BackColor="#EFF1F1"
ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="110" ItemStyle-Width="110">
</asp:BoundField>
</Columns>
</asp:GridView>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#CCCC99" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
<RowStyle BackColor="#F7F7DE" />
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#FBFBF2" />
<SortedAscendingHeaderStyle BackColor="#848384" />
<SortedDescendingCellStyle BackColor="#EAEAD3" />
<SortedDescendingHeaderStyle BackColor="#575357" />
</asp:GridView>
</asp:Panel>
<asp:Button ID="btn" runat="server" Text="Delete" onclick="btn_Click" />
Sample Images
http://i.stack.imgur.com/ZM96f.jpg
http://i.stack.imgur.com/ULWTM.jpg
删除按钮的代码
Code for delete button
protected void btn_Click(object sender, EventArgs e)
{
foreach (GridViewRow gvRow1 in gvCustomers.Rows)
{
GridView gv = (GridView)gvRow1.FindControl("gvOrders");
foreach (GridViewRow gvrow in gv.Rows)
{
CheckBox chkBoxChild = (CheckBox)gvrow.FindControl("chkBoxChild");
if (chkBoxChild.Checked)
{
}
}
}
}
Unable to execute my condition when I select a check box and running the code. Any help please. Also how can I work out Select All check box scenario in the child grid view.
推荐答案
通过为子网格视图制作
EnableViewState="true"
,我得到了必需的
这篇关于子GridView失去对按钮单击的关注的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!