2011-06-23 9 views
0

オブジェクトデータソースにバインドされたフォームビュー内にあるリピーター内のテキストボックスの値を取得します。フォームビュー内にあるリピーター内のテキストフィールドからデータを取得

<asp:FormView ID="FormView1" runat="server" AllowPaging="True" 
    DataKeyNames="Id" EnableViewState="False" 
    OnPageIndexChanging="FormView1_PageIndexChanging" 
    onitemupdated="FormView1_ItemUpdated" 
    OnItemUpdating="FormView1_ItemUpdating" ondatabound="FormView1_DataBound"> 
    <ItemTemplate> 
     <asp:TextBox ID="txtProdName" runat="server" Text='<%#Eval("ManufacturerProductName") %>'></asp:TextBox> 
     <asp:Repeater ID="Repeater1" runat="server" DataSource='<%#DataBinder.Eval(Container.DataItem,"Distributors") %>'> 
      <ItemTemplate> 
       <asp:TextBox ID="TextBox1" runat="server" ontextchanged="onTextChanged" Text='<%# DataBinder.Eval(Container.DataItem, "FobCost")%>'></asp:TextBox> 
       <asp:Repeater ID="Repeater2" runat="server" DataSource='<%# DataBinder.Eval(Container.DataItem,"PricingsheetWarehouses") %>'> 
        <ItemTemplate> 
         <asp:TextBox ID="TextBox2" runat="server" ontextchanged="onTextChanged" Text='<%# DataBinder.Eval(Container.DataItem, "DeliveredCost")%>'></asp:TextBox> 
        </ItemTemplate> 
       </asp:Repeater> 
      </ItemTemplate> 
     </asp:Repeater> 
    </ItemTemplate> 
</asp:FormView> 

私はこの

TextBox t=FormView1.FindControl("txtProdname")as textBox; 

としてtxtProdNameを取得するが、私はテキストボックスのは私に ヌル任意の助けを与えるリピーター内部を得るためにそれを使用することはできません?

答えて

0

FormView1でそれをやっているだけで、リピーター自体の中のテキストボックスを見つける必要があります。

0

関係なく、それがどのようになるの深い制御を見つけないように再帰的な検索を使用し

Repeater repeater1=FormView1.FindControl("Repeater1")as Repeater; 

protected void RptrSupplier_ItemDataBound(Objectsender,System.Web.UI.WebControls.RepeaterItemEventArgs e) 
{ 
    // Only process items (not footers or headers) 
    if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) 
    { 
      TextBox t = e.Item.FindControl("TextBox1") as TextBox; 
      t.ID = ((MyType)e.Item.DataItem).ID.ToString(); //you should cast to the type of your object 
      t.TextChanged += txt1_TextChanged; 
    } 
} 

protected void txt1_TextChanged(object sender, EventArgs e) 
{ 
    TextBox t = sender as TextBox; 
    var tempobject = MyCollection.Where(C => C.ID == t.ID).Single(); 
    tempobject.Prop = t.Text; 
} 
+0

これを置けばいいのどのイベントでヌル... – user780975

+0

としてええ、この1つの戻りトンコード?最初のステートメントは 'FormView'バインディングイベントの内側に、2番目のステートメントは' repeater'バインディングイベントの内側になければなりません。 –

+0

私は自分の答えを編集しました。 –

0

を試してみてください。

public static Control FindControlRecursive(Control control, string id) 
    { 
     if (control == null) return null; 
     Control ctrl = control.FindControl(id); 
     if (ctrl == null) 
     { 
      foreach (Control child in control.Controls) 
      { 
       ctrl = FindControlRecursive(child, id); 
       if (ctrl != null) break; 
      } 
     } 
     return ctrl; 
    } 
+0

thnx私はこれを試して私はコントロールのテキストボックスを見つけるが、私に古い値を与えていないものを編集... – user780975

関連する問題