0
<asp:Panel ID="pnlGrdShift" runat="server" ScrollBars="Auto" Width="900px" Height="520px" CssClass="srcColor">
            <cc1:GridView  ID="gvShift" runat="server" AutoGenerateColumns="False" AllowSorting="True"
               CssClass="grid"
               OnDataBound="gvShift_DataBound" 
               DataSourceID="odsShiftDetails" 
               AllowPaging="True" 
               ShowFooter="false"
               onrowcancelingedit="gvShift_RowCancelingEdit" 
               onrowcommand="gvShift_RowCommand" 
               onrowdeleting="gvShift_RowDeleting" 
               onrowediting="gvShift_RowEditing" 
               onrowupdating="gvShift_RowUpdating" 
               OnSelectedIndexChanged="gvShift_SelectedIndexChanged" 
               OnRowDataBound="gvShift_RowDataBound">        
                <AlternatingRowStyle CssClass="altrowstyle"  />
                <HeaderStyle CssClass="headerstyle" />
                <RowStyle CssClass="rowstyle" Wrap="false"  />
                <EmptyDataRowStyle BackColor="#edf5ff" Height="300px" VerticalAlign="Middle" HorizontalAlign="Center" />
                <EmptyDataTemplate >
                    No Records Found
                </EmptyDataTemplate> 
                <Columns>
                    <asp:TemplateField HeaderText="E Code" SortExpression="userecode" HeaderStyle-Font-Bold="true" HeaderStyle-Font-Names="Calibre" HeaderStyle-ForeColor="White">
                        <ItemTemplate>
                            <asp:Label ID="lblUserECode" runat="server" Text='<%#Eval("userecode") %>' CssClass="GridContent" />                    
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:Label ID="lblEditUserECode" runat="server" Text='<%#Eval("userecode") %>' style="width:50px;" CssClass="GridContent" />                    
                        </EditItemTemplate>
                    </asp:TemplateField>                       

                    <asp:TemplateField HeaderText="User Name" SortExpression="username" HeaderStyle-Font-Bold="true" HeaderStyle-Font-Names="Calibre" HeaderStyle-ForeColor="White">
                        <ItemTemplate>
                            <asp:Label ID="lblUserName" runat="server" Text='<%#Eval("username") %>' CssClass="GridContent" />                    
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:Label ID="lblEditUserName" runat="server" Text='<%#Eval("username") %>' style="width:100px;" CssClass="GridContent"/>                    
                        </EditItemTemplate>
                    </asp:TemplateField>


                    <asp:TemplateField HeaderText="Shift Start Time" SortExpression="ShiftStartTime" HeaderStyle-Font-Bold="true" HeaderStyle-Font-Names="Calibre" HeaderStyle-ForeColor="White">
                         <ItemTemplate>
                            <asp:Label ID="lblShiftStartTime" runat="server" Text='<%#Eval("ShiftStartTime") %>'  CssClass="GridContent"/>                    
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="ddlShiftStartTime" runat="server" Text='<%#Eval("ShiftStartTime") %>' style="width:65px;" CssClass="GridContent" />
                            <asp:RegularExpressionValidator ID="RegularExpValidatorddlShiftStartTime" runat="server" ControlToValidate="ddlShiftStartTime" ValidationExpression="^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$" ErrorMessage="*" Font-Bold="true" ForeColor="Red" ToolTip="Must be in HH:MM" />                            

                        </EditItemTemplate>                            
                    </asp:TemplateField>  

                    <asp:TemplateField HeaderText="Shift End Time" SortExpression="ShiftEndTime" HeaderStyle-Font-Bold="true" HeaderStyle-Font-Names="Calibre" HeaderStyle-ForeColor="White">
                        <ItemTemplate>
                            <asp:Label ID="lblShiftEndTime" runat="server" Text='<%#Eval("ShiftEndTime") %>' CssClass="GridContent" />                    
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="ddlShiftEndTime" runat="server" Text='<%#Eval("ShiftEndTime") %>' style="width:65px;" CssClass="GridContent"  />
                            <asp:RegularExpressionValidator ID="RegularExpValidatorddlShiftEndTime" runat="server" ControlToValidate="ddlShiftEndTime" ValidationExpression="^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$" ErrorMessage="*" Font-Bold="true" ForeColor="Red" ToolTip="Must be in HH:MM" />                            

                        </EditItemTemplate>                            
                    </asp:TemplateField>
                        <%--<asp:BoundField DataField="ShiftEndTIme" HeaderText="Shift End Time" SortExpression="ShiftEndTIme"/>--%>
                    <asp:TemplateField HeaderText="Saturday Shift Start Time" SortExpression="WeekendShiftStartTime" HeaderStyle-Font-Bold="true" HeaderStyle-Font-Names="Calibre" HeaderStyle-ForeColor="White">
                        <ItemTemplate>
                            <asp:Label ID="lblWeekendShiftStartTime" runat="server" Text='<%#Eval("WeekendShiftStartTime") %>' CssClass="GridContent" />                    
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="ddlWeekendShiftStartTime" runat="server" Text='<%#Eval("WeekendShiftStartTime") %>' style="width:65px;" CssClass="GridContent" />  
                            <asp:RegularExpressionValidator ID="RegularExpValidatorddlWeekendShiftStartTime" runat="server" ControlToValidate="ddlWeekendShiftStartTime" ValidationExpression="^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$" ErrorMessage="*" Font-Bold="true" ForeColor="Red" ToolTip="Must be in HH:MM" />                          

                        </EditItemTemplate>
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Saturday Shift End Time" SortExpression="weekendshiftendtime" HeaderStyle-Font-Bold="true" HeaderStyle-Font-Names="Calibre" HeaderStyle-ForeColor="White">
                    <ItemTemplate>
                            <asp:Label ID="lblWeekendShiftEndTime" runat="server" Text='<%#Eval("weekendshiftendtime") %>' CssClass="GridContent"/>                    
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="ddlWeekendShiftEndTime" runat="server" Text='<%#Eval("weekendshiftendtime") %>' style="width:65px;" CssClass="GridContent" /> 
                            <asp:RegularExpressionValidator ID="RegularExpValidatorddlWeekendShiftEndTime" runat="server" ControlToValidate="ddlWeekendShiftEndTime" ValidationExpression="^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$" ErrorMessage="*" Font-Bold="true" ForeColor="Red" ToolTip="Must be in HH:MM" />                           

                        </EditItemTemplate>                           
                    </asp:TemplateField>

                    <asp:TemplateField  ShowHeader="False" > 
                        <EditItemTemplate> 
                          <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update" Text="Update" ForeColor="White"></asp:LinkButton> 
                          <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" ForeColor="White"></asp:LinkButton> 
                        </EditItemTemplate> 
                        <ItemTemplate> 
                          <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit" ForeColor="White"></asp:LinkButton> 
                        </ItemTemplate> 
                </asp:TemplateField>                    
           </Columns>
                <PagerTemplate >
                     <table width="100%" >
                        <tr>
                            <td style="text-align:  left">
                                Page Size: 
                                    <asp:DropDownList ID="ddPageSize" runat="server" EnableViewState="true" OnSelectedIndexChanged="ddPageSize_SelectedIndexChanged" AutoPostBack="true" style="width:50px;">
                                    <asp:ListItem Text="10" ></asp:ListItem>
                                    <asp:ListItem Text="20" ></asp:ListItem>
                                    <asp:ListItem Text="30" ></asp:ListItem>
                                    <asp:ListItem Text="40" ></asp:ListItem>
                                    <asp:ListItem Text="50" ></asp:ListItem>
                                </asp:DropDownList>
                            </td>
                            <td style="text-align: right">
                                <asp:Label ID="lblPageCount" runat="server"></asp:Label>
                            </td>
                        </tr>
                    </table>
                </PagerTemplate>
                </cc1:GridView>      
         </asp:Panel></td></tr>
                </table>
                                                       <div style="margin-top:5px" class="PagerGrid">
                <asp:DataPager  ID="pager" runat="server" PagedControlID="gvShift">
                    <Fields>                                            
                        <asp:NextPreviousPagerField FirstPageText="&lt;&lt;" LastPageText="&gt;&gt;" 
                            NextPageText="&gt;"  PreviousPageText="&lt;" ShowFirstPageButton="True"
                            ShowNextPageButton="False" ButtonCssClass="datapager"  />
                        <asp:NumericPagerField ButtonCount="10"  NumericButtonCssClass="datapager" CurrentPageLabelCssClass="datapager"   />
                        <asp:NextPreviousPagerField LastPageText="&gt;&gt;" NextPageText="&gt;" 
                            ShowLastPageButton="True" ShowPreviousPageButton="False" ButtonCssClass="datapager" />
                    </Fields>
                </asp:DataPager>
            </div>
            <br />
            <asp:ObjectDataSource ID="odsShiftDetails" runat="server" 
                SelectMethod="GetShiftInfoSortedPage" TypeName="EQ.DAL.ShiftInfoDB"
                EnablePaging="True" SelectCountMethod="GetShiftInfoCount" 
                SortParameterName="sortExpression">
                <SelectParameters>
                    <asp:ControlParameter  ControlID="hfSearchCriteria"  Name="searchCriteria" Direction="Input"  />
                </SelectParameters>                                            
            </asp:ObjectDataSource>

行更新の背後にあるコードは次のとおりです:-

protected void gvShift_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        try
        {
            TextBox txtShiftStartTime = (TextBox)gvShift.Rows[e.RowIndex].FindControl("ddlShiftStartTime");
            TextBox txtShiftEndTime = (TextBox)gvShift.Rows[e.RowIndex].FindControl("ddlShiftEndTime");
            TextBox txtWeekendShiftStartTime = (TextBox)gvShift.Rows[e.RowIndex].FindControl("ddlWeekendShiftStartTime");
            TextBox txtWeekendShiftEndTime = (TextBox)gvShift.Rows[e.RowIndex].FindControl("ddlWeekendShiftEndTime");
            Label lblUserecode = (Label)gvShift.Rows[e.RowIndex].FindControl("lblEditUserECode");

            string userecode = lblUserecode.Text.ToString();
            string _ShiftStart = txtShiftStartTime.Text.ToString();
            string _ShiftEnd = txtShiftEndTime.Text.ToString();
            string _WeekendShiftStart = txtWeekendShiftStartTime.Text.ToString();
            string _WeekendShiftend = txtWeekendShiftEndTime.Text.ToString();

            EmployeeQuotientCL.Entities.ConfigurationVariables _configVariables = new ConfigurationVariables();
            string databaseConnectionString = _configVariables.ConnectionString;
            SqlConnection sqlConnection = null;
            if (((databaseConnectionString + string.Empty) != string.Empty))
            {
                DBConnect dbConnect = new DBConnect(_configVariables.ConnectionString);
                sqlConnection = dbConnect.SQLConnection;
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = sqlConnection;
                cmd.CommandText = "UPDATE UserInfo SET ShiftStartTime ='" + _ShiftStart + "',ShiftEndTime='" + _ShiftEnd.ToString() + "',Weekendshiftstarttime='" + _WeekendShiftStart.ToString() + "',Weekendshiftendtime='" + _WeekendShiftend.ToString() + "'   WHERE UserECode=" + userecode.ToString();
                sqlConnection.Open();
                cmd.ExecuteNonQuery();
                gvShift.DataSource = null;
                gvShift.DataBind();
                sqlConnection.Close();
            }
        }
        catch (Exception ex)
        {
        }
    }

grid の行を更新しているときに、次のエラー メッセージが表示されます。

Microsoft JScript ランタイム エラー: Sys.WebForms.PageRequestManagerServerErrorException: > UpdateMethod が指定されていない限り、ObjectDataSource 'odsShiftDetails' では更新がサポートされていません。

このエラーを修正する方法を教えてください。前もって感謝します。

4

1 に答える 1

0

グリッドビューに update メソッドを追加する必要があります。このチュートリアルを見てください: Gridview ObjectdataSource

于 2012-11-15T08:29:11.723 に答える