Asp.net AjaxControlToolkit-GridView无法选择-不了解viewstate

Asp.net AjaxControlToolkit-GridView无法选择-不了解viewstate,asp.net,gridview,ajaxcontroltoolkit,Asp.net,Gridview,Ajaxcontroltoolkit,概述: 我在表格顶部有两个文本框,用于输入开始/结束日期。 在窗体的中间,我有一个基于这些日期的行填充的GRIDVIEW。 在表单的底部,我有一个根据网格中选择的行生成的报告 我选择了开始日期和结束日期,gridview开始运行。当我单击网格中某一行上的“选择”按钮时,发生了一些使其中断的事情。未选择该行。我之所以知道这一点,是因为通常默认情况下应用于gridview中选定行的CSS没有应用 另外,在我设置的代码背后 lblGridError.Text = gridJobsReport.Sele

概述:

我在表格顶部有两个文本框,用于输入开始/结束日期。 在窗体的中间,我有一个基于这些日期的行填充的GRIDVIEW。 在表单的底部,我有一个根据网格中选择的行生成的报告

我选择了开始日期和结束日期,gridview开始运行。当我单击网格中某一行上的“选择”按钮时,发生了一些使其中断的事情。未选择该行。我之所以知道这一点,是因为通常默认情况下应用于gridview中选定行的CSS没有应用

另外,在我设置的代码背后

lblGridError.Text = gridJobsReport.SelectedIndex.ToString()
页面加载甚至有相同的代码,因此页面加载时标签显示为-1,但在我单击gridview上的选择按钮时标签不会更改。有东西破坏了我的异步回发。我希望我能更好地理解viewstate,我一直怀疑它是罪魁祸首,但老实说,我不知道

<%@ Page Title="" Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="false" CodeFile="BidReport.aspx.vb" Inherits="BidReport" %>

<%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server"> 
    </asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server"> 
            <ajaxToolkit:ToolkitScriptManager ID="tsmgrJobsReport" runat="server" 
                CombineScripts="True">
            </ajaxToolkit:ToolkitScriptManager>
        <p>
            Enter a date range to populate the Jobs Grid.</p>
        <asp:UpdatePanel ID="uPanelForm" runat="server">
            <ContentTemplate>
                <table>
                    <tr>
                        <td style="text-align: right">
                            <asp:Label ID="lblBeginningDate" runat="server" Text="Beginning Date:"></asp:Label></td>
                        <td>
                            <asp:TextBox ID="txtBeginningDate" runat="server" AutoPostBack="True" 
                                CausesValidation="True"></asp:TextBox>
                            <ajaxToolkit:CalendarExtender ID="txtBeginningDate_CalendarExtender" 
                                runat="server" 
                                TargetControlID="txtBeginningDate">
                            </ajaxToolkit:CalendarExtender>
                        </td>
                        <td>
                            <asp:RequiredFieldValidator ID="rfvBeginningdate" runat="server" 
                                ControlToValidate="txtBeginningDate" 
                                ErrorMessage="You must enter the Beginning Date" Font-Bold="True" 
                                ForeColor="Red">*</asp:RequiredFieldValidator>
                            <asp:RegularExpressionValidator ID="revBeginningDate" runat="server" 
                                ControlToValidate="txtBeginningDate" 
                                ErrorMessage="Posted Date must be in the format &quot;DD/MM/YYYY&quot;" 
                                Font-Bold="True" ForeColor="Red" 
                                ValidationExpression="^([1-9]|1[012])/([1-9]|[12][0-9]|3[01])/(20\d\d)$">*</asp:RegularExpressionValidator>
                        </td>
                        <td rowspan="2">
                            <asp:CompareValidator ID="cvBeginDateLTEndDate" runat="server" 
                                ControlToCompare="txtEndingDate" ControlToValidate="txtBeginningDate" 
                                ErrorMessage="Beginning Date must be earlier than the Ending Date." 
                                Font-Bold="True" ForeColor="Red" Operator="LessThan">*</asp:CompareValidator>
                        </td>
                    </tr>
                    <tr>
                        <td style="text-align: right">
                            <asp:Label ID="lblEndingDate" runat="server" Text="Ending Date:"></asp:Label></td>
                        <td>
                            <asp:TextBox ID="txtEndingDate" runat="server" AutoPostBack="True" 
                                CausesValidation="True"></asp:TextBox>

                            <ajaxToolkit:CalendarExtender ID="txtEndingDate_CalendarExtender" 
                                runat="server" TargetControlID="txtEndingDate">
                            </ajaxToolkit:CalendarExtender>
                        </td>
                        <td>
                            <asp:RequiredFieldValidator ID="rfvEndingDate" runat="server" 
                                ControlToValidate="txtEndingDate" 
                                ErrorMessage="You must enter the EndingDate Date" Font-Bold="True" 
                                ForeColor="Red">*</asp:RequiredFieldValidator>
                            <asp:RegularExpressionValidator ID="revEndingDate" runat="server" 
                                ControlToValidate="txtEndingDate" 
                                ErrorMessage="Posted Date must be in the format &quot;DD/MM/YYYY&quot;" 
                                Font-Bold="True" ForeColor="Red" 
                                ValidationExpression="^([1-9]|1[012])/([1-9]|[12][0-9]|3[01])/(20\d\d)$">*</asp:RegularExpressionValidator>
                        </td>
                    </tr>
                </table>
        <asp:ValidationSummary ID="valsumDates" runat="server" ForeColor="Red" />

        <p>Click or Tap the &quot;SELECT&quot; button in the right column next to the Job you want and 
            a report will be generated below.</p>

                <asp:GridView ID="gridJobsReport" runat="server" AutoGenerateColumns="False" 
                            CellPadding="4" DataKeyNames="PostingID" DataSourceID="sqlDSReportGrid" 
                            ForeColor="#333333" GridLines="Horizontal" 
                            ShowHeaderWhenEmpty="True" Width="100%">
                            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                            <Columns>
                                <asp:BoundField DataField="PostingID" HeaderText="PostingID" ReadOnly="True" 
                                    SortExpression="PostingID" >
                                    <ItemStyle HorizontalAlign="Center" />
                                    </asp:BoundField>

                                <asp:BoundField DataField="Department" HeaderText="Department" 
                                    SortExpression="Department" />

                                <asp:BoundField DataField="JobName" HeaderText="JobName" 
                                    SortExpression="JobName" />

                                <asp:BoundField DataField="Shift" HeaderText="Shift" SortExpression="Shift" >
                                    <ItemStyle HorizontalAlign="Center" />
                                    </asp:BoundField>

                                <asp:BoundField DataField="Needs" HeaderText="Needs" 
                                    SortExpression="Needs" >
                                    <ItemStyle HorizontalAlign="Center" />
                                    </asp:BoundField>

                                <asp:BoundField DataField="PostedDate" HeaderText="PostedDate" 
                                    SortExpression="PostedDate" DataFormatString="{0:d}" >
                                    <ItemStyle HorizontalAlign="Center" />
                                    </asp:BoundField>

                                <asp:BoundField DataField="PostedTime" HeaderText="Time" 
                                    SortExpression="PostedTime" DataFormatString="{0:t}" >
                                    <ItemStyle HorizontalAlign="Center" />
                                    </asp:BoundField>

                                <asp:BoundField DataField="ClosingDate" HeaderText="ClosingDate" 
                                    SortExpression="ClosingDate" DataFormatString="{0:d}" >
                                    <ItemStyle HorizontalAlign="Center" />
                                    </asp:BoundField>

                                <asp:BoundField DataField="ClosingTime" HeaderText="Time" 
                                    SortExpression="ClosingTime" DataFormatString="{0:t}" >
                                    <ItemStyle HorizontalAlign="Center" />
                                    </asp:BoundField>

                                <asp:CommandField ButtonType="Button" CausesValidation="True"
                                    ShowSelectButton="true" />
                            </Columns>
                            <EditRowStyle BackColor="#999999" />
                            <EmptyDataRowStyle HorizontalAlign="Center" />
                            <EmptyDataTemplate>
                                There is currently no data to display based on the date range provided.
                            </EmptyDataTemplate>
                            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                            <SortedAscendingCellStyle BackColor="#E9E7E2" />
                            <SortedAscendingHeaderStyle BackColor="#506C8C" />
                            <SortedDescendingCellStyle BackColor="#FFFDF8" />
                            <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
                        </asp:GridView>
                        <br />
                    <asp:Label ID="lblGridError" runat="server"></asp:Label>
            </ContentTemplate>
        </asp:UpdatePanel>
            <ajaxToolkit:UpdatePanelAnimationExtender ID="uPanelForm_UpdatePanelAnimationExtender" 
                runat="server" TargetControlID="uPanelForm">
            </ajaxToolkit:UpdatePanelAnimationExtender>
        <p>You can print or save the report using the buttons at the top of the report.</p>
        <asp:UpdatePanel ID="uPanelJobsReport" runat="server">
            <ContentTemplate>
                <rsweb:ReportViewer ID="rvJobsReport" runat="server" Width="100%">
                    </rsweb:ReportViewer>

            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="gridJobsReport" 
                    EventName="SelectedIndexChanged" />
            </Triggers>
        </asp:UpdatePanel>

        <asp:SqlDataSource ID="sqlDSReportGrid" runat="server" 
                ConnectionString="<%$ ConnectionStrings:JobsDB %>" 
                SelectCommand="SELECT dbo.tblJobPostings.PostingID, dbo.tblDepartments.Department, dbo.tblJobs.JobName, 
                                    dbo.tblJobPostings.Shift, dbo.tblJobPostings.Needs, dbo.tblJobPostings.PostedDate, 
                                    dbo.tblJobPostings.PostedTime, dbo.tblJobPostings.ClosingDate, dbo.tblJobPostings.ClosingTime 
                                FROM dbo.tblJobPostings 
                                    INNER JOIN dbo.tblJobs ON dbo.tblJobPostings.JobID = dbo.tblJobs.JobID 
                                    INNER JOIN dbo.tblDepartments ON dbo.tblJobPostings.DeptID = dbo.tblDepartments.DeptID 
                                WHERE dbo.tblJobPostings.ClosingDate &gt;= @BeginningDate 
                                    AND dbo.tblJobPostings.ClosingDate &lt;= @EndingDate 
                                ORDER BY dbo.tblJobPostings.ClosingDate Asc">
            <SelectParameters>
                <asp:ControlParameter ControlID="txtBeginningDate" Name="BeginningDate" 
                    PropertyName="Text" ConvertEmptyStringToNull="False" DefaultValue="" />
                <asp:ControlParameter ControlID="txtEndingDate" Name="EndingDate" 
                    PropertyName="Text" ConvertEmptyStringToNull="False" DefaultValue="" />
            </SelectParameters>
        </asp:SqlDataSource>

        <asp:SqlDataSource ID="sqlDSJobReport" runat="server"></asp:SqlDataSource>

</asp:Content>

我真的不明白为什么会这样,但我决定尝试用会话变量手动处理日期,现在它工作得很好。不管我是否弄乱了更新面板上的会话状态或任何表单元素,不管现在发生什么,它似乎都能工作

我猜在初始异步回发之后,sqldatasource没有读取文本框中的值或其他内容。如果有人能在另一个回答问题部分解释发生了什么,我会接受的

If Page.IsPostBack Then

    Session("sBeginningDate") = txtBeginningDate.Text
    Sessoin("sEndingDate") = txtEndingDate.Text

    txtBeginningDate.Text = Session("sBeginningdate")
    txtEndingDate.Text = Session("sEndingDate")

Else

    Session("sBeginningDate") = Now().AddDays(-14)
    Session("sEndingDate") = Now()

    txtBeginningDate.Text = Session("sBeginningDate").ToShortDateString
    txtEndingDate.Text = Session("sEndingDate").ToShortDateString

End If

从第一篇文章开始,我尝试了很多东西。我认为问题可能是在文本框更改时更新我的sqldata源。