2011-05-04 79 views
1

我試圖從detailview中獲取值到formview。我想將formview插入文本框中的Book ID/ISBN設置爲detailsview中的Book ID/ISBN值。在插入模式下從DetailsView獲取值到FormView文本框

這裏是我的代碼示例:

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

所以我想要做的是,當用戶單擊插入/儲量書LinkBut​​ton的圖書ID/ISBN已經被設置到Book ID /默認情況下,formview插入模式下的ISBN。

任何幫助將不勝感激;)

在此先感謝。

回答

1

你可以嘗試檢查DetailsView1.SelectedValue

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

編輯: 現在,如果你想該值綁定到你的DetailsView你插入功能,也不會表現得像其他的控制,因爲你正在使用其他控件的Bind method,並提供雙向綁定。

現在您需要將該值傳遞給插入的evet,就像我們使用DetailsView1.SelectedValue分配值但不綁定該值。

我希望你能理解這個理論。

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

嗨!感謝它的工作,但它沒有綁定到記錄。我如何綁定,以便用戶只能輸入保留日期? – Loupi 2011-05-04 06:05:47

+0

檢查我的編輯部分。解決您目前的問題。 – 2011-05-04 06:15:55

+0

謝謝!我仍在研究它,我會試着看看我能否把它做好。 – Loupi 2011-05-04 06:50:42

相關問題