Answered by:
Problems with Update from DataGrid

Question
-
User-1048278357 posted
Hello
I have the Problem that the update does not save the text of a BoundField
<asp:TemplateField HeaderText = "Beschreibung"> <ItemTemplate> <asp:Label ID="LABEL0" runat="server" Text='<%# Eval("E_TEXT")%>' /> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="TEXT" runat="server" Text='<%# Bind("E_TEXT")%>' TextMode="MultiLine" OnTextChanged="SelectedTextChanged" AutoPostBack="true" Width="350" Height="100"/> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText = "Eventart"> <ItemTemplate> <asp:Label ID="LABEL1" runat="server" Text='<%# Eval("E_STATUS")%>' /> </ItemTemplate> <EditItemTemplate> <asp:DropDownList ID="DropDownList1" OnSelectedIndexChanged="SelectedIndexChanged" AutoPostBack="true" runat="server" CssClass="Input" Width="100" SelectedValue='<%# Bind("E_STATUS")%>'> <asp:ListItem Value="Privat"> Privat </asp:ListItem> <asp:ListItem Value="Öffentlich"> Öffentlich </asp:ListItem> <asp:ListItem Value="Stream"> Stream </asp:ListItem> </asp:DropDownList> </EditItemTemplate> </asp:TemplateField>
The E_TEXT is working correctly. The E_STATUS is showing correctly on editing, but after update it is empty.
updatestring:
UpdateCommand="update EVENT set E_NAME = @E_NAME, E_TEXT = @E_TEXT, E_STATUS = @E_STATUS, E_WO = @E_WO, E_WANN = @E_WANN, E_START = @E_START, E_DOOR = @E_DOOR, E_PREIS = @E_PREIS, E_LIMIT = @E_LIMIT, E_SOFTLIMIT = @E_SOFTLIMIT where E_ID = @E_ID" />
and code behind
Protected Sub OnRowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) If e.Row.RowType = DataControlRowType.DataRow Then Dim drv As DataRowView = TryCast(e.Row.DataItem, DataRowView) Dim ddlCategories As DropDownList = TryCast(e.Row.FindControl("DropDownList1"), DropDownList) If ddlCategories IsNot Nothing Then ddlCategories.SelectedValue = drv("E_STATUS").ToString() End If End If End Sub Protected Sub SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Dim ddl As DropDownList = DirectCast(sender, DropDownList) Dim row As GridViewRow = TryCast(ddl.NamingContainer, GridViewRow) Dim ddlv As String = DirectCast(sender, DropDownList).SelectedValue If row IsNot Nothing Then row.Cells(5).Text = ddlv End If End Sub
hope for somebody who can help
Thursday, July 16, 2020 11:44 AM
Answers
-
User475983607 posted
Simply, you are not using the GridView as intended. Remove the auto post back events and use the GridView's update button to update the record.
https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.gridview?view=netframework-4.8
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, July 16, 2020 11:54 AM
All replies
-
User475983607 posted
Simply, you are not using the GridView as intended. Remove the auto post back events and use the GridView's update button to update the record.
https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.gridview?view=netframework-4.8
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, July 16, 2020 11:54 AM -
User-1048278357 posted
Thank you. works perfect
Thursday, July 16, 2020 2:23 PM