0

I have an ajax tab which inside has a grid, on this grid there is a check box where the user has the ability to check it and assign it to a technician, but for some reason im unable to reference the control, the grid has a total of 4 rows so there is data there, this is my code which is run of a button click

protected void btnAllocate_click(object sender, EventArgs e)
        {
            foreach (System.Web.UI.Control s in tbHappyCall.Controls)
            {
               foreach (GridViewRow Row in gvHappyCall.Rows)
                {
                    CheckBox chkAllocate = (CheckBox)Row.FindControl("chkAllocate");

                    if (chkAllocate.Checked)
                    {
                        HyperLink lblOrderID = (HyperLink)Row.FindControl("hyperOrderID");

                        HappyCallManager objHappyCallManager = new HappyCallManager();

                        objHappyCallManager.HappyCallAllocated(Convert.ToInt64(lblOrderID.Text), objWebuser.ShortAbbr, ddlAllocateTo.SelectedValue);

                        //Update database with person details thats are assigned to the Welcome Call

                    }
                }
            }
        }

when it goes on to the Foreach gridviewrow etc the count is 1 even though there is 4 rows displaying information ?

Can any one shed any light on this? or even better a solution?

Thank you for your time.

UPdate

<ajaxToolkit:TabPanel ID="tbHappyCall" runat="server" HeaderText="Welcome Calls" TabIndex="10">
                <ContentTemplate>
                    <%--OnRowDataBound="gvConfirmOrder_rowDataBound"--%>
                    <div id="divHappyCall">
                        <asp:GridView ID="gvHappyCall" runat="server" AutoGenerateColumns="false" class="tablesorter"
                            EmptyDataText="There is no Record to display." DataKeyNames="OrderID" EnableViewState="false"
                            OnRowDataBound="gvHappyCall_RowDataBound">
                            <AlternatingRowStyle CssClass="NormalTextVNC" BackColor="#E2E9E7"></AlternatingRowStyle>
                            <Columns>
                                <asp:TemplateField HeaderText="Account Manager">
                                    <ItemTemplate>
                                        <asp:Label ID="lblAccountManager" CssClass="gvItem" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.AccountManager") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="OrderID">
                                    <ItemTemplate>
                                        <asp:HyperLink ID="hyperOrderID" runat="server" ForeColor="White" NavigateUrl='<%#Eval("OrderGuid","/Documents/HappyCall.aspx?OrderID={0}") %>'
                                            Text='<%#Eval("OrderID") %>'></asp:HyperLink>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Customer Name">
                                    <ItemTemplate>
                                        <asp:Label ID="lblCustomerName" CssClass="gvItem" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.CustomerName") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Company Name">
                                    <ItemTemplate>
                                        <asp:Label ID="lblCompanyName" CssClass="gvItem" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.CompanyName") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Mobile Number">
                                    <ItemTemplate>
                                        <asp:Label ID="lblMobileNumber" CssClass="gvItem" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.MobileNumber") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Dispatch Date">
                                    <ItemTemplate>
                                        <asp:Label ID="lblConnectionDate" CssClass="gvItem" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.DespatchDate") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Status">
                                    <ItemTemplate>
                                        <asp:Label ID="lblStatus" CssClass="gvItem" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Status") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>  
                               <asp:BoundField headertext="Date Called" dataformatstring="{0:dd/MM/yyyy}"   datafield="EditedDate" HeaderStyle-Width="100px"  />
                                <asp:TemplateField HeaderText="Allocated To">
                                    <ItemTemplate>
                                        <asp:Label ID="lblAllocatedTo" CssClass="gvItem" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.AllocatedTo") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                            <%--<asp:TemplateField HeaderText="Last Action">
                                    <ItemTemplate>
                                        <asp:Label ID="lblLAstAction" CssClass="gvItem" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.LastAction") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>--%>
                                <asp:TemplateField HeaderText="Check">
                                    <ItemTemplate>
                                      <asp:CheckBox runat="server" ID="chkAssignWelcomeCall" />
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                        </asp:GridView>
                        <asp:DropDownList runat="server" ID="ddlAllocateTo" CssClass="floatright">
                        <asp:ListItem>Name of Admin to Allocate</asp:ListItem>
                        </asp:DropDownList>
                        <div class="WhiteSpace"></div>
                        <asp:Button runat="server" ID="btnAllocate" class="floatright" Text="Allocate" OnClick="btnAllocate_click" />
                    </div>
                </ContentTemplate>
            </ajaxToolkit:TabPanel>

4

1 回答 1

0

澄清一下:你不需要迭代你的控件集合TabPanel来找到你的GridView,它是直接可用的,不要混淆它的Controls.Count数量GridView.Rows.Count

ViewState 是否在某处被禁用?

编辑:我看到 GridView 的 ViewState 被禁用。我假设它在您启用它时起作用。

于 2012-09-03T09:44:29.833 回答