0
아래와 같이 DetailsView
및 SqlDataSource
이 있습니다. NotesTB
과 NameTB
은 코드 뒤에 null이 아니며 입력 된 새 값을 유지하지 않습니다. 원래 바인드 된 이전 값을 반환합니다. 나는 인터넷을 수색하고 이것을위한 이유를 찾아 낼 수없고 그것을 당황하게하고있다.DetailsView OnUpdating TextBox가 새 텍스트를 반환하지 않습니다. ASP.NET C#
<asp:DetailsView ID="PhotoDetailsDV" runat="server" Height="50px" Width="125px" DefaultMode="Edit" AutoGenerateRows="False" DataKeyNames="PhotoID" DataSourceID="XXXXXXXXXX" OnDataBound="PhotoDetailsDV_DataBound" OnItemUpdating="PhotoDetailsDV_ItemUpdating1" >
<Fields>
<asp:TemplateField HeaderText="Notes" SortExpression="Notes">
<EditItemTemplate>
<asp:TextBox ID="NotesTB" runat="server" Text='<%# Bind("Notes") %>'></asp:TextBox>
<asp:HiddenField runat="server" ID="PhotoIdHF" Value='<%# Bind("PhotoID") %>'/>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="NotesLabel" runat="server" Text='<%# Bind("Notes") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name" SortExpression="Name">
<EditItemTemplate>
<asp:TextBox ID="NameTB" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="NameLabel" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource runat="server" ID="XXXXX" ConnectionString="<%$ ConnectionStrings:XXXXXXXXXXXXXXX %>" SelectCommand="SELECT [Notes], Photoid, [Name] FROM [XXXXXXXX] WHERE ([FileID] = @FileID)" UpdateCommand="UPDATE [XXXXXXX] SET [Notes] = @Notes, [Name] = @Name WHERE [PhotoID] = @PhotoID">
<SelectParameters>
<asp:Parameter Name="FileID" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="Notes" Type="String" />
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="PhotoID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
protected void PhotoDetailsDV_ItemUpdating1(object sender, DetailsViewUpdateEventArgs e)
{
TextBox NameTB = (TextBox) PhotoDetailsDV.FindControl("NameTB");
TextBox NotesTB = (TextBox) PhotoDetailsDV.FindControl("NotesTB");
e.NewValues["Notes"] = NotesTB.Text;//here NotesTB.Text is "" even when something is entered or it is the old value
e.NewValues["Name"] = NameTB.Text;//here NameTB.Text is "" even when something is entered or it is the old value
}
백엔드 바인드 코드를 게시 할 수 있습니까? 바인드를 포함하지 않은 것 같습니다! IsPostback –
백엔드 바인드 코드 란 무엇입니까? –
코드를 디테일 뷰에 바인딩하십시오. 포스트 백 이후에 데이터를 다시 바인딩하지 않도록하려면 포스트 백 조건을 사용합니까? –