<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>
How can we write JQuery function to get Dropdownlist from Details View? I need to alert user if there is any change in Dropdownlist. im writing something like this but it is not getting fired when dropdown values is changed by user.
$(document).ready(function () {
$(#ddlGroups).change(function () {
alert("Hello world!");
});
});
[EDIT] I have one more question. Based on the dropdown selection I need to get the corresponding Description from the ObjectDataSource. Here is the Server Side Code.
Can you please give me equivalent JQuery function?
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;
}
}
I was trying something like this in JQuery, but it doesn’t work.
$(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);
}
});
});
I am assuming this “DropDownList” can be rendered with a different “clientID” , you can try this: