2011-08-02 9 views
0
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"  DataSourceID="TimeEntriesDataSource" 
          RowStyle-VerticalAlign="Top" DefaultMode="Insert" HeaderStyle-HorizontalAlign="Center" 
          BackColor="White" BorderColor="#336666" BorderStyle="Double" BorderWidth="3px" 
          CellPadding="4" OnItemInserted="DetailsView1_ItemInserted" OnItemCommand="DetailsView1_ItemCommand" 
          OnItemInserting="DetailsView1_ItemInserting"> 
          <RowStyle VerticalAlign="Top" BackColor="White" ForeColor="#333333"></RowStyle> 
          <PagerStyle BackColor="#336666" ForeColor="White" HorizontalAlign="Center" /> 
          <Fields> 
           <asp:TemplateField HeaderText="Group"> 
            <InsertItemTemplate> 
             <asp:DropDownList ID="ddlGroups" runat="server"  DataSourceID="GroupsDataSource" DataTextField="Name" 
              DataValueField="Id" AppendDataBoundItems="true" ValidationGroup="InsertTimeEntry" 
              AutoPostBack="true" OnSelectedIndexChanged="ddlGroups_SelectedIndexChanged"> 
              <asp:ListItem Selected="True" Text="-- Select --" Value=""></asp:ListItem> 
             </asp:DropDownList> 

             <asp:ObjectDataSource ID="GroupsDataSource" runat="server" SelectMethod="GetSortedActiveGroups" 
              TypeName="NicorNational.TimeTracker.BLL.Gateway"></asp:ObjectDataSource> 
            </InsertItemTemplate> 
           </asp:TemplateField> 

          </Fields> 
          <EditRowStyle Font-Bold="True" /> 
      </asp:DetailsView> 

詳細ビューからドロップダウンリストを取得するにはどうすればよいですか?ドロップダウンリストに変更がある場合、ユーザーに警告する必要があります。私はこのようなことを書いていますが、ユーザーによってドロップダウン値が変更されても解雇されません。JQueryを使用してDetailView内のコントロールを取得するには

   $(document).ready(function() { 
          $(#ddlGroups).change(function() { 
           alert("Hello world!"); 
          }); 
         }); 

[編集]もう1つ質問があります。ドロップダウンの選択に基づいて、私はObjectDataSourceから対応するDescriptionを取得する必要があります。ここにサーバーサイドコードがあります。 同等のJQuery関数を教えてください。

   protected void ddlActivityTypes_SelectedIndexChanged(object sender, EventArgs e) 
        { 
         string description = string.Empty; 
         var ddlActivityTypes = DetailsView1.FindControl("ddlActivityTypes") as DropDownList; 
         var textBox1 = DetailsView1.FindControl("TextBox1") as TextBox; 
         var activityDataSource = DetailsView1.FindControl("ActivityTypesDataSource") as ObjectDataSource; 

         if (!string.IsNullOrEmpty(ddlActivityTypes.SelectedValue)) 
         { 
          IEnumerable IDs = activityDataSource.Select(); 

          foreach (ActivityType item in IDs) 
          { 
           if (item.Name == ddlActivityTypes.SelectedItem.Text.ToString()) 
           { 
            description = item.Description; 
           } 
          } 

          textBox1.Text = description; 
         } 

        } 

私はjQueryのでは、このような何かをしようとしていたが、それは動作しません。

    $(document).ready(function() { 
         $('select[id*=ddlGroups]').change(function() { 
          alert("Hello world!"); 
         }); 
        }); 

答えて

1

マスターページやネストされたコントロールなどを使用している場合はこちらをお試しください。

+0

素晴らしいです! – CodeNinja

+0

すばらしい解決策。 – brenjt

0

このコントロールがページにレンダリングされるとIDが同じではないかもしれない:私は、この「DropDownListコントロールは、」異なる「クライアントID」でレンダリングすることが可能と仮定すると、あなたはこれを試すことができています

    $(document).ready(function() { 
         $('select[id*=ddlActivityTypes]').change(function() { 
          var selectedText = $('select[id*=ddlActivityTypes]').find("option:selected").text(); ; 
          var data = $('select[id*=ActivityTypesDataSource]').select(); 

          data.each(function() { 
           if (selectedText == this.Name) { 
            alert(this.description); 
           } 

         }); 
        }); 
関連する問題