在下面的代碼中,我有一個gridview內的下拉列表,我想獲取下拉列表的id。在哪裏我得到對象引用error.I嘗試下面的代碼它拋出對象引用的錯誤在頁面上加載。請幫我解決這個問題。要獲取在gridview下拉的Id
$(document).ready(OnReady);
function OnReady() {
//Handle the change event for the drop down list
$("#ddlLocation").change(onChange);
}
function onChange() {
//create the ajax request
$.ajax
(
{
type: "POST", //HTTP method
url: "NewIndent.aspx/OnContinentChange", //page/method name
data: "{'continentName':'" + $("#<%=ddlLocation.ClientID%>").val() + "'}", //json to represent argument
contentType: "application/json; charset=utf-8",
dataType: "json",
success: callback,
error: onError
}
);
}
//Handle the callback on success
function callback(msg) {
//it shows object object
var val = msg.d;
var countries = val.split(';');
var length = countries.length;
//var ID = gvProduct.DataKeys[e.Row.RowIndex]["ddlProduct"].ToString();
document.getElementById('<%=gvProduct.FindControl("ddlProduct").ClientID%>').options.length = 0;
// var Ier = gvProduct.DataKeys[e.Row.RowIndex]["ddlProduct"].ToString();
var dropDown = document.getElementById('<%=gvProduct.FindControl("ddlProduct").ClientID%>');
for (var i = 0; i < length - 1; ++i) {
var option = document.createElement("option");
option.text = countries[i];
option.value = countries[i];
dropDown.options.add(option);
}
}
//Handle the callback on error
function onError() {
alert('something went wrong');
}
<asp:GridView Width="100%" runat="server" ID="gvProduct" AutoGenerateColumns="false" CellPadding="4" ForeColor="#333333" ShowFooter="true"
PageSize-Mode="NumericPages" PageSize="10" PagerStyle-Visible="true" AllowPaging="true" AllowSorting="true"
CssClass="mGrid" OnRowDataBound="gvProduct_RowDataBound" OnRowDeleting="gvProduct_RowDeleting"
PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt">
<asp:TemplateField HeaderText="Product Name" ItemStyle-Width="350px">
<ItemTemplate>
<asp:DropDownList ID="ddlProduct" runat="server" OnSelectedIndexChanged="ddlProduct_SelectedIndexChanged" AutoPostBack="true" Style="width: 100%; height:23px" ></asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</asp:GridView>
你想在GridView中使用_which_'DropDownList'的ID嗎?網格中的每一行都包含該下拉列表。 – 2014-09-23 13:51:39
@Tim Schmelter是的,我想獲得內部網格下拉的id(ddlProduct)。 – user3930037 2014-09-23 13:53:47
@Tim Schmelter我想獲得id = ddlProduct的下拉列表 – user3930037 2014-09-23 13:57:11