在插入模式下从DetailsView获取值到FormView文本框

发布于 2024-11-04 19:07:19 字数 4815 浏览 5 评论 0原文

我正在尝试从详细信息视图到表单视图获取价值。我想将表单视图插入文本框中的图书 ID/ISBN 设置为详细信息视图中的图书 ID/ISBN 值。

这是我的代码示例:

<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
            CellPadding="4" DataKeyNames="bookid" DataSourceID="detailsDataSource" 
            ForeColor="#333333" GridLines="None" Height="50px" Width="">
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <CommandRowStyle BackColor="#D1DDF1" Font-Bold="True" />
            <RowStyle BackColor="#EFF3FB" />
            <FieldHeaderStyle BackColor="#DEE8F5" Font-Bold="True" />
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
            <FooterTemplate>
                <asp:GridView ID="GridView2" runat="server" AllowPaging="True" 
                    AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" 
                    DataKeyNames="reservationid" DataSourceID="reserveDataSource" 
                    ForeColor="#333333" GridLines="None">
                    <RowStyle BackColor="#EFF3FB" />
                    <Columns>
                        <asp:BoundField DataField="EmployeeID" HeaderText="Reserved by" 
                            SortExpression="EmployeeID" />
                        <asp:BoundField DataField="reservedate" HeaderText="Reserved date" 
                            SortExpression="reservedate" />
                    </Columns>
                    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                    <EditRowStyle BackColor="#2461BF" />
                    <AlternatingRowStyle BackColor="White" />
                </asp:GridView>
                <asp:FormView ID="FormView1" runat="server" DataKeyNames="reservationid" 
                    DataSourceID="reserveDataSource">
                    <EditItemTemplate>
                        reservationid:
                        <asp:Label ID="reservationidLabel1" runat="server" 
                            Text='<%# Eval("reservationid") %>' />
                        <br />
                        bookid:
                        <asp:TextBox ID="bookidTextBox" runat="server" Text='<%# Bind("bookid") %>' />
                        <br />
                        EmployeeID:
                        <asp:TextBox ID="EmployeeIDTextBox" runat="server" 
                            Text='<%# Bind("EmployeeID") %>' />
                        <br />
                        reservedate:
                        <asp:TextBox ID="reservedateTextBox" runat="server" 
                            Text='<%# Bind("reservedate") %>' />
                        <br />
                        <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
                            CommandName="Update" Text="Update" />
                        &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" 
                            CausesValidation="False" CommandName="Cancel" Text="Cancel" />
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        Book ID/ISBN:
                        <asp:TextBox ID="bookidTextBox" runat="server" 
                        Text='<%# Bind("bookid") %>'/>
                        <br />
                        Employee ID:
                        <asp:TextBox ID="EmployeeIDTextBox0" runat="server" 
                            Text='<%# Bind("EmployeeID") %>' />
                        <br />
                        Reserve date:
                        <asp:TextBox ID="reservedateTextBox0" runat="server" 
                            Text='<%# Bind("reservedate") %>' />
                        <br />
                        <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" 
                            CommandName="Insert" Text="Reserve" />
                        &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" 
                            CausesValidation="False" CommandName="Cancel" Text="Cancel" />
                    </InsertItemTemplate>

所以我想做的是,当用户单击“插入/保留图书”链接按钮时,图书 ID/ISBN 已默认设置为 formview 插入模式下的图书 ID/ISBN。

任何帮助将不胜感激;)

提前致谢。

I'm trying to get the value from detailsview to formview. I want to set the Book ID/ISBN in formview insert textbox to Book ID/ISBN value from detailsview.

Here's a sample of my code:

<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
            CellPadding="4" DataKeyNames="bookid" DataSourceID="detailsDataSource" 
            ForeColor="#333333" GridLines="None" Height="50px" Width="">
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <CommandRowStyle BackColor="#D1DDF1" Font-Bold="True" />
            <RowStyle BackColor="#EFF3FB" />
            <FieldHeaderStyle BackColor="#DEE8F5" Font-Bold="True" />
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
            <FooterTemplate>
                <asp:GridView ID="GridView2" runat="server" AllowPaging="True" 
                    AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" 
                    DataKeyNames="reservationid" DataSourceID="reserveDataSource" 
                    ForeColor="#333333" GridLines="None">
                    <RowStyle BackColor="#EFF3FB" />
                    <Columns>
                        <asp:BoundField DataField="EmployeeID" HeaderText="Reserved by" 
                            SortExpression="EmployeeID" />
                        <asp:BoundField DataField="reservedate" HeaderText="Reserved date" 
                            SortExpression="reservedate" />
                    </Columns>
                    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                    <EditRowStyle BackColor="#2461BF" />
                    <AlternatingRowStyle BackColor="White" />
                </asp:GridView>
                <asp:FormView ID="FormView1" runat="server" DataKeyNames="reservationid" 
                    DataSourceID="reserveDataSource">
                    <EditItemTemplate>
                        reservationid:
                        <asp:Label ID="reservationidLabel1" runat="server" 
                            Text='<%# Eval("reservationid") %>' />
                        <br />
                        bookid:
                        <asp:TextBox ID="bookidTextBox" runat="server" Text='<%# Bind("bookid") %>' />
                        <br />
                        EmployeeID:
                        <asp:TextBox ID="EmployeeIDTextBox" runat="server" 
                            Text='<%# Bind("EmployeeID") %>' />
                        <br />
                        reservedate:
                        <asp:TextBox ID="reservedateTextBox" runat="server" 
                            Text='<%# Bind("reservedate") %>' />
                        <br />
                        <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
                            CommandName="Update" Text="Update" />
                         <asp:LinkButton ID="UpdateCancelButton" runat="server" 
                            CausesValidation="False" CommandName="Cancel" Text="Cancel" />
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        Book ID/ISBN:
                        <asp:TextBox ID="bookidTextBox" runat="server" 
                        Text='<%# Bind("bookid") %>'/>
                        <br />
                        Employee ID:
                        <asp:TextBox ID="EmployeeIDTextBox0" runat="server" 
                            Text='<%# Bind("EmployeeID") %>' />
                        <br />
                        Reserve date:
                        <asp:TextBox ID="reservedateTextBox0" runat="server" 
                            Text='<%# Bind("reservedate") %>' />
                        <br />
                        <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" 
                            CommandName="Insert" Text="Reserve" />
                         <asp:LinkButton ID="InsertCancelButton" runat="server" 
                            CausesValidation="False" CommandName="Cancel" Text="Cancel" />
                    </InsertItemTemplate>

So what I'm trying to do is when a user click the Insert/Reserve book linkbutton the Book ID/ISBN is already set to the Book ID/ISBN in formview insert mode as default.

Any help would be much appreciated ;)

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

画骨成沙 2024-11-11 19:07:19

您可以尝试检查 DetailsView1.SelectedValue

<asp:TextBox ID="bookidTextBox" runat="server" 
                    Text='<%# DetailsView1.SelectedValue %>'/>

编辑:
现在,如果您想将该值绑定到 DetailsView 的 Insert 函数,它的行为将不会像其他控件一样,因为您正在使用另一个控件的 Bind 方法并且它提供了两种方式的绑定。

现在,您需要将该值传递给 DetailsView 的插入事件,就像我们使用 DetailsView1.SelectedValue 分配值但不绑定该值一样。

我希望你能理解这个理论。

protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
{
    e.Values["bookid"] = ((TextBox)DetailsView1.FindControl("bookidTextBox")).Text;
}

Can you try and check the DetailsView1.SelectedValue

<asp:TextBox ID="bookidTextBox" runat="server" 
                    Text='<%# DetailsView1.SelectedValue %>'/>

Edit:
Now if you want to bind that value to your Insert function of your DetailsView, it will not behave like the other control, since you are using the Bind method for the other control and it provides two way binding.

Now you need to pass that value to inserting evet of DetailsView like as we are assigning values using DetailsView1.SelectedValue but not binding the value.

I hope you understand this theory.

protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
{
    e.Values["bookid"] = ((TextBox)DetailsView1.FindControl("bookidTextBox")).Text;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文