Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# DetailsView On更新文本框不返回新文本ASP.NET C_C#_Asp.net_Detailsview - Fatal编程技术网

C# DetailsView On更新文本框不返回新文本ASP.NET C

C# DetailsView On更新文本框不返回新文本ASP.NET C,c#,asp.net,detailsview,C#,Asp.net,Detailsview,我有一个DetailsView和一个SqlDataSource,如下所示。NotesTB和NameTB在代码隐藏中不为null,但不保留在中输入的新值。它们将返回最初绑定的旧值。我在网上搜索过,找不到原因,这让我很困惑 <asp:DetailsView ID="PhotoDetailsDV" runat="server" Height="50px" Width="125px" DefaultMode="Edit" AutoGenerateRows="False" DataKeyNames=

我有一个DetailsView和一个SqlDataSource,如下所示。NotesTB和NameTB在代码隐藏中不为null,但不保留在中输入的新值。它们将返回最初绑定的旧值。我在网上搜索过,找不到原因,这让我很困惑

<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>

代码将您的数据绑定到detailview,是否使用not is回发条件确保回发后不会重新绑定数据?

是否可以发布后端绑定代码?看来你没有把bind包括进去!ISPostback后端绑定代码是什么意思?将数据绑定到detailview的代码,是否使用not is回发条件确保回发后不会重新绑定数据?这一点很好。我忘了带钥匙了!我回来了。我现在在家,但我会在早上的工作中解决这个问题。如果你能给我一个答案,我会在早上接受它,如果它有效的话。
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
    }