简体   繁体   English

gridview更新/插入列

[英]gridview updating/inserting the columns

am editing and updateing the gridview columns but it not taking the values. 我正在编辑和更新gridview列,但没有使用这些值。 and it not show the error. 并没有显示错误。

plz tell the suggestion. 请告诉我这个建议。 how to do the updated. 如何做更新。 if am click on edit it enable. 如果是单击编辑启用。 when am enter the values it not updating the db. 当我输入值时,它不会更新数据库。

if (ViewState["LeaveManagementID"] == null)

        {

                foreach (GridViewRow row in gvLeaves.Rows)
                {

                    EP_LeaveManagementRow leaveUpdateRow = db.EP_LeaveManagementCollection.GetRow("LeaveManagementID=" + gvLeaves.DataKeys[e.RowIndex].Value);

                    if (leaveUpdateRow != null)
                    {
                        leaveUpdateRow.NoOfDays = int.Parse(lblNoOfDays.Text.ToString());


                        db.EP_LeaveManagementCollection.Update(leaveUpdateRow);
                        ViewState["LeaveManagementID"] = leaveUpdateRow.LeaveManagementID;

                        mvLeaveManagement.SetActiveView(vwLeavesDetails);

ASPX ASPX

   <asp:TemplateField HeaderText="Comments">
                                            <ItemStyle HorizontalAlign="Left" VerticalAlign="Middle"></ItemStyle>
                                            <HeaderStyle Width="15%" HorizontalAlign="Left" VerticalAlign="Middle"></HeaderStyle>
                                             <ItemTemplate>
                                                        <asp:Label ID="lblComments" Visible="false" runat="server" ></asp:Label>

                                                    </ItemTemplate>
                                            <EditItemTemplate>
                                            <asp:TextBox ID="txtComments" runat="server" MaxLength="50" TextMode="MultiLine"  Text='<%#Bind("LeaveCommants") %>'></asp:TextBox>
                                            </EditItemTemplate>

                                        </asp:TemplateField>


 <asp:TemplateField HeaderText="Edit/Update" HeaderStyle-Width="25%">
                                                <ItemTemplate>

                                                    <asp:LinkButton ID="lkbEdit" Text="Edit" runat="server" CommandName="Edit"  />
                                                    <%-- <asp:LinkButton ID="lkbUpdate" Text="Update" runat="server" CommandName="Update"  />--%>


                                                </ItemTemplate>
                                               <EditItemTemplate>

                                                    <asp:LinkButton ID="btnUpdate" Text="Update" runat="server" CommandName="Update" />
                                                    <asp:LinkButton ID="btnCancel" Text="Cancel" runat="server" CommandName="Cancel" />

                                                </EditItemTemplate>
                                            </asp:TemplateField>

如果您想使用GridView向数据库中插入删除和更新数据,请按照以下链接进行操作: -http : //csharpdotnetfreak.blogspot.com/2009/05/gridview-sqldatasource-insert-edit.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM