<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函數從Details View中獲取Dropdownlist?如果Dropdownlist中有任何更改,我需要提醒用戶。即時通訊寫這樣的東西,但它不會被觸發時,下拉值由用戶更改。使用JQuery控制DetailView內部DetailView
$(document).ready(function() {
$(#ddlGroups).change(function() {
alert("Hello world!");
});
});
[編輯]我還有一個問題。基於下拉選擇,我需要從ObjectDataSource中獲取相應的描述。這是服務器端代碼。 你能給我等價的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*=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);
}
});
});
太棒了!它工作! – CodeNinja
偉大的解決方案。 – brenjt