本文介绍了GridView中的RowEditing无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在尝试将GridView中的记录模式更改为编辑模式,即当用户单击GridView中的编辑按钮编辑特定记录时。 我使用以下代码: protected void GridView1_RowEditing( object sender,GridViewEditEventArgs e) { GridView1.EditIndex = e.NewEditIndex; GridView1.DataBind(); } Gridview结构(.aspx)是: < asp:GridView ID = GridView1 runat = server AutoGenerateDeleteButton = True AutoGenerateEditButton = True CellPadding = 4 ForeColor = #333333 GridLines = 无 OnRowEditing = GridView1_RowEditing DataKeyNames = DwgRegID OnRowUpdating = Gri dView1_RowUpdating OnRowDeleting = GridView1_RowDeleting OnRowCancelingEdit = GridView1_RowCancelingEdit OnRowUpdated = GridView1_RowUpdated > < AlternatingRowStyle BackColor = 白色 ForeColor = #284775 /> < EditRowStyle BackColor = #999999 /> < FooterStyle BackColor = #5D7B9D Font-Bold = True ForeColor = 白色 /> < HeaderStyle BackColor = #5D7B9D Font-Bold = True ForeColor = 白色 /> < PagerStyle BackColor = #284775 ForeColor = 白色 Horizo​​ntalAlign = 中心 /> < 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 > 当我点击gridview中的编辑按钮时,而不是更改记录状态编辑模式,程序崩溃。 请帮忙。 问候解决方案 让我解释一下。你在更新时试图填写gridview,这意味着在编辑时没有数据。所以你必须先用data填充你的gridview.Make函数说fillgrid(),并在这里第一次绑定您的gridview。当您调用行编辑事件( OnRowEditing =GridView1_RowEditing)时,请进行如下更改 protected void GridView1_RowEditing( object sender,GridViewEditEventArgs e) { GridView1.EditIndex = e.NewEditIndex; fillgrid(); } 这样可行。 问候......:笑: 参考这个 URL 它可以为你提供帮助... 如何编辑n更新网格视图中的行 [ ^ ] I am trying to change a record mode in a GridView to "Edit-Mode" i.e., when user clicks on Edit button in GridView to edit a specific record.I using the following code:protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e){ GridView1.EditIndex = e.NewEditIndex; GridView1.DataBind(); }Gridview structure (.aspx) is: <asp:GridView ID="GridView1" runat="server" AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" CellPadding="4" ForeColor="#333333" GridLines="None" OnRowEditing="GridView1_RowEditing" DataKeyNames="DwgRegID" OnRowUpdating="GridView1_RowUpdating" OnRowDeleting="GridView1_RowDeleting" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowUpdated="GridView1_RowUpdated" > <AlternatingRowStyle BackColor="White" ForeColor="#284775" /> <EditRowStyle BackColor="#999999" /> <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>When I click on Edit button in the gridview, instead of changing record state to edit-mode, program crashes. Please help.Regards 解决方案 Let me explain you.You tried to fill gridview at the time of updating,that means there would be no data at the time of editing.so you have to first fill your gridview with data.Make function say fillgrid(),and bind your gridview here for first time. When you call your row editing event(OnRowEditing="GridView1_RowEditing"),make change like thisprotected void GridView1_RowEditing(object sender, GridViewEditEventArgs e){ GridView1.EditIndex = e.NewEditIndex; fillgrid();}This will work.Regards.. :laugh:Refer this URL it can be help full for you...How to edit n update a row in GRID VIEW[^] 这篇关于GridView中的RowEditing无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-13 17:12