使用jquery设置asp.net下拉列表默认值 [英] setting the asp.net dropdownlist default value with jquery

查看:89
本文介绍了使用jquery设置asp.net下拉列表默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在隐藏弹出窗口中有一个asp:DropDownList控件,当用户点击Gridview控件的一行上的图标(图像)时,会激活此弹出窗口。



然后我使用一些jquery来选择已被点击的行,然后我在gridview行上提取标签控件的值,然后想要填充弹出域(文本框控件和DropDown列表控件)默认值),想法是使用它们来更新数据库中行中的记录。



问题我正在填充下拉控件中的默认选择在弹出窗口上。我可以填充文本框中的文本框,而不是下拉列表。



这是其中一个文本框的标记和来自gridview的ddl我在哪里找到我的值:

I have a asp:DropDownList control in a hidden popup, this popup is activated when the user clicks on an icon(image) on a row of a Gridview Control.

Then i use some jquery to select the row that''s been clicked on and then i extract the values of the label controls on the gridview row and then want to populate the popup fields (Text box controls and the DropDown list controls default value), the idea being to use them to update the record in the row in the database.

The issue im having is populating the default selection in the dropdown control on the popup. I can populate the text boxes in the textboxes, just not the dropdown.

Here is the markup for one of the textboxes and the ddl from the gridview where i source my values:

<asp:TemplateField HeaderText="Current Stage"> 
	<ItemTemplate> 
		<asp:Label ID="lblCurrentStage" CssClass="clCurrentStage" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "CurrentStage")%>' ToolTip ='<%# DataBinder.Eval(Container.DataItem, "CurrentStage")%>'></asp:Label>
	</ItemTemplate>
	</asp:TemplateField>
	<asp:TemplateField HeaderText="Review Date"> 
	<ItemTemplate> 
		<asp:Label ID="lblReviewDate" CssClass="clReviewDate" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "ReviewDate")%>' ToolTip ='<%# DataBinder.Eval(Container.DataItem, "ReviewDate")%>'></asp:Label>
	</ItemTemplate> 
</asp:TemplateField>        



,这里的代码在文本框上工作正常但不在ddl上:


and here is the code that works fine on the textbox but not on the ddl:

<div id="PopUpTrackerEditFieldCurrentStage">
	<div class="clEditFieldCurrentStageContainer">
	<asp:DropDownList ID="ddlPopUpEditCurrentStage" runat="server"> </asp:DropDownList>
	</div>
</div>
<div id="PopUpTrackerEditFieldReviewDate">
	<div class="clEditFieldReviewDateContainer">
	<asp:TextBox ID="tbPopUpEditReviewDate"  CssClass="clPopUpDateFieldsInEdit" runat="server" Text=""  ToolTip =""></asp:TextBox>
	</div>
</div>





这里是用于填充文本框和下拉列表的jquery:



And here is jquery used to populate the textbox and dropdown list:

//Store the current row being edited
var row = $(this).closest("tr");
//Get the existing Comments into a string
var strCurrentStage = $(".clCurrentStage", row).text();
//Add the any existing Comments
$("#<%=ddlPopUpEditCurrentStage.ClientID%>").val(strCurrentStage);
//Dynamically add the text to the tooltip 
$("#<%=ddlPopUpEditCurrentStage.ClientID%>").attr('title', 'Click to select the current stage here for ' + strPSTNNum);
//Get the existing Review Date into a string
var strReviewDate = $(".clReviewDate", row).text();
//Add the any existing Review Date
$("#<%=tbPopUpEditReviewDate.ClientID%>").val(strReviewDate);
//Dynamically add the text to the tooltip 
$("#<%=tbPopUpEditReviewDate.ClientID%>").attr('title', 'Edit the review date here for ' + strPSTNNum);





我知道strCurrentStage没问题,因为我暂时用它来填充文本框,以查看它是否包含gridview中当前舞台标签的当前舞台文本,它确实如此。所以我认为问题是我无法选择下拉列表控件的正确部分来填充默认值。



I know strCurrentStage is ok because i temporaraly used it to populate the textbox to see if it contained the current stage text from the current stage label in the gridview and it did. So the issue i think is that i cannot select the correct part of the dropdown list control to populate the default value in.

推荐答案

this )。nearest( tr);
// 将现有注释转换为字符串
var strCurrentStage =
(this).closest("tr"); //Get the existing Comments into a string var strCurrentStage =


。 clCurrentStage,row).text();
// 添加任何现有评论
(".clCurrentStage", row).text(); //Add the any existing Comments


#<%= ddlPopUpEditCurrentStage.ClientID%>)。val(strCurrentStage);
// 将文本动态添加到工具提示
("#<%=ddlPopUpEditCurrentStage.ClientID%>").val(strCurrentStage); //Dynamically add the text to the tooltip


这篇关于使用jquery设置asp.net下拉列表默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆