Click here to Skip to main content
15,670,097 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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"> 
		<asp:Label ID="lblCurrentStage" CssClass="clCurrentStage" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "CurrentStage")%>' ToolTip ='<%# DataBinder.Eval(Container.DataItem, "CurrentStage")%>'></asp:Label>
	<asp:TemplateField HeaderText="Review Date"> 
		<asp:Label ID="lblReviewDate" CssClass="clReviewDate" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "ReviewDate")%>' ToolTip ='<%# DataBinder.Eval(Container.DataItem, "ReviewDate")%>'></asp:Label>

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 id="PopUpTrackerEditFieldReviewDate">
	<div class="clEditFieldReviewDateContainer">
	<asp:TextBox ID="tbPopUpEditReviewDate"  CssClass="clPopUpDateFieldsInEdit" runat="server" Text=""  ToolTip =""></asp:TextBox>

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
//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
//Dynamically add the text to the tooltip 
$("#<%=tbPopUpEditReviewDate.ClientID%>").attr('title', 'Edit the review date here for ' + strPSTNNum);

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.
Updated 17-May-13 5:47am
Can you post the rendered html in browser of that dropdown only ?
MoiD101 20-May-13 4:51am    
Hi here it is;
<div id="PopUpTrackerEditFieldCurrentStage">
<div class="clEditFieldCurrentStageContainer">
<select name="ctl00$MainContent$ddlPopUpEditCurrentStage" id="MainContent_ddlPopUpEditCurrentStage">
Hare there are no options inside select tag.
So, what you want to do ? You want to add an option or select an existing option ?

But there are no options, so I guess you want to add one option ? Please reply.
MoiD101 20-May-13 5:37am    
Yes i was thinking over the weekend why this is not applying my default selection as coded above and it has occurred to me that there MUST be an existing list of options already in place in the dropdown; one of which is an option that matches the 'strCurrenStage' contents i'm trying to set as the default populated option.

so in summary; i need to have a dropdown with the options present to set the default value to match from?
If you want to add some predefined options, then you can directly do that from the mark-up aspx page by adding some ListItems inside the Dropdown. What is the problem ?

1 solution

The problem was that once the dropdownlist was populated the DOM would not let me select the dropdown list to select the default value. unless i do it at the same time as the just after adding the options from the database.

function getListOfStages() {
    var ddlCurrentStages = $("#<%=ddlPopUpEditCurrentStage.ClientID%>");
        type: "POST",
        url: "PSTN_OrderManagementTracker.aspx/PopCurrentStagesddl",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
            var xmlDoc = $.parseXML(response.d);
            var xml = $(xmlDoc);
            var CurrentStagesReturned = xml.find("Table");
            //for each current stage from the database, add it to the dropdown list on the modal
            $.each(CurrentStagesReturned, function (index, CurrentStagesReturned) {
                dbCurrentStageName = $(this).find("CurrentStage").text()
                ddlCurrentStages.append('<option>' + dbCurrentStageName + '</option>');
                //Get the this records existing current stage into a string
                var strCurrentStage = $(".clCurrentStage", row).text();
                //Add the existing current stage for that record as the default one showing

        failure: function (msg) {
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900