简体   繁体   中英

gridview updating/inserting the columns

am editing and updateing the gridview columns but it not taking the values. 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

   <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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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